You are not using UITableViewController's
initialisation method. Instead, use
TableViewViewController *tableViewController = [[TableViewController alloc] initWithStyle:UITableViewStylePlain];
[self.navigationController pushViewController:tableViewController animated:YES];
After that, initialising your table view inside your UITableViewController
class is pointless, because UITableViewController
is already doing that for you (that's the point of using it) and instead, access the tableView
property with self.tableView
.
Also note that - (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier
is only available for iOS 6.0 and above (will crash below that)
And for populating the cell just use :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [NSString stringWithFormat:@"row %d", indexPath.row + 1];
return cell;
}