I’m adding a UITableView as a subview to my view; it’s a subview because I’m splitting my view into two subviews. I’m new to Objective-C so I am certain it’s a rookie mistake.
Here is my code:
@interface DishDetailViewController()
{
NSMutableArray *_test;
}
@end
The title property of the object dish is an 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;
}
You haven’t set the datasource or delegate of the table: