开发者

Iphone sdk : Where to put code for a grouped table

开发者 https://www.devze.com 2022-12-24 03:55 出处:网络
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.

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消