views:

22

answers:

2

I have a root view controller with no nib file,

I tried adding this at cellForRowAtIndexPath as that passes in a UITableView as tableView.

So I put :

tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];

It ran with no error but it didnt seem to change anything.

A: 

Did you add the tableView to your view ?

[self.view addSubview:tableView];
FenchKiss Dev
+1  A: 

Your code snippit won't change anything, because the -tableView:cellForRowAtIndexPath: method is only called when an existing table view needs to know how to draw its content. No existing table view, no getting called.

Remove that line from your -tableView:cellForRowAtIndexPath: method, and define a UITableView object either:

  • In the XIB file (this is the easiest approach)
  • In the initialisation code for your view controller

As @FenchKiss Dev wrote, if you set up the table in code you need to add it as a subview to an existing view, for it to be displayed.

Graham Lee