tableView:cellForRowAtIndexPath: method question
First of all I beg your pardon but I am a newbie and trying to learn Objective-C. I开发者_如何学C was studying the UITableView when I found this method:
tableView:cellForRowAtIndexPath:
I read the reference for UITableView and some examples but I don't understand one thing: what calls this method and what validates its parameters (eg. indexPath)?
This method is called by the UITableView when the table needs another cell to display. The table view calls the tableView:cellForRowAtIndexPath:
method on the object pointed to with the table view's dataSource
property.
So if you've got a view controller, you implement the tableView:cellForRowAtIndexPath:
there, call [myTableView setDataSource:self]
and the table view will call tableView:cellForRowAtIndexPath:
once it needs to display a new cell for the given index path (row).
Of course, you also need to implement the other required method tableView:numberOfRowsInSection
of the UITableViewDataSource
protocol and maybe a few other of its methods. Otherwise the table view would even know how many sections and rows it should display.
精彩评论