开发者

Display array in UITableView when in UIViewController

I have a tableview in my开发者_如何学JAVA viewcontroller. But i have an error which say that [tableview:numberofrowinsection:]:unrecongized selector sent to instance. Can someone please tell me how cna i solve this.


You need to set the UIViewController as the delegate, and also datasource also you need to implement the necessary methods. if you look in the apple docs they are described there but i think the main ones are:

  • numberOfSectionsInTableView:
  • tableView:numberOfRows:inSection:
  • and tableView:cellForRowAtIndexPath:

in the first one you return the number of sections, usually 1, in the second you return the number of rows for the section( usually the count of the array) and in the final you return the UITableViewCell object with the necessary data put in position.

read the apple docs, and if necessary copy the method names from one of the UITableViewController templates.

hope this helps


Create a new file using the UITableViewController template - it has skeleton code that should help (even if you don't use it to build on, you can use it as an example of implementing the delegate methods and reusing cells).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜