I have a root view controller w开发者_Go百科ith 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.
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.
Did you add the tableView to your view ?
[self.view addSubview:tableView];
精彩评论