UiableView как SubView?
-
30-09-2019 - |
Вопрос
Это возможно? Я просто хочу небольшой стол в моем нынешнем виде ... вот что я пытаюсь сделать:
.h Файл
#import <UIKit/UIKit.h>
@interface IngredientsRootView : UIViewController <UITableViewDelegate, UITableViewDataSource> {
UITableView *ingredientsTable;
}
@property (nonatomic, retain) UITableView *ingredientsTable;
@end
.m Файл у меня есть делегирование и методы источника данных и этот код:
ingredientsTable = [[UITableView alloc] initWithFrame:CGRectMake(10, 10, 300, 300) style:UITableViewStylePlain];
[ingredientsTable setDelegate:self];
[ingredientsTable setDataSource:self];
[self.view addSubview:ingredientsTable];
Приложение не врезается, но он не показывает таблицу. На данный момент я просто установил все определенно согласно:
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 10;
}
// the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = @"Hello";
return cell;
}
Что я делаю неправильно? Спасибо
Решение
Попробуйте позвонить -reloadData
На табличном представлении после добавления его в качестве подзрена.
Кроме того, как настроен вид? Это создано в XIB или через -loadView
?
Другие советы
Вы вспомнили, чтобы добавить [window addSubview:[IngredientsRootView view]];
к вашему приложению делегата?
И кстати, вместо унаследования от UIViewController вы можете просто наследовать от UiableViewController, и вы получите все эти функциональные возможности для вас без добавленного кода.