Я добавляю UITableView
как подпредставление к моему представлению;это подпредставление, потому что я разделяю свое мнение на два подпредставления.Я новичок в Objective-C, поэтому я уверен, что это ошибка новичка.
Вот мой код:
@interface DishDetailViewController()
{
NSMutableArray *_test;
}
@end
Свойство title
объекта dish
являетсяNSString
.
-(void) viewDidLoad
{
[super viewDidLoad];
NSMutableArray *test = [[NSMutableArray alloc]init];
[test addObject:dish.title];
}
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.title = @"Dish Detail";
UIView *_view = [[UIView alloc]init];
_view.backgroundColor = [UIColor whiteColor];
self.view = _view;
int widthTable= 300;
UITableView *table =[[UITableView alloc] initWithFrame:CGRectMake(0,0, widthTable, self.view.frame.size.height)];
[self.view addSubview:table];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_test count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CELL";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.text = [_test objectAtIndex:indexPath.row];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return dish.user;
}