I HAVE READ apple documentation and it’s not understandable for such a beginner in Objective-C as me. I’m trying to implement multicolumn UITableView following this link example and it just doesn’t work so i need to comprehend how cellForRowAtIndexPath work, cause for me personally this method seems pretty complicated.
1) What does it return? UITableViewCell? But why does it look so odd?
-(UITableViewCell *)tableView:(UITableView *)tableView
- What is that? Could you please explain?
2) How does it get called and what is more important how am i to connect it to a certain UITableView??? What if i have two UITableView‘s named firstTableView and secondTableView and i want them to be different (to perform cellForRowAtIndexPath differently)? How am i supposed to link my UITableViews to this
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
the method accepts NSIndexPath, not UITableView. What am i gonna do?
1) The function returns a cell for a table view yes? So, the returned object is of type
UITableViewCell. These are the objects that you see in the table’s rows. This function basically returns a cell, for a table view.But you might ask, how the function would know what cell to return for what row, which is answered in the 2nd question
2)
NSIndexPathis essentially two things-Because your table might be divided to many sections and each with its own rows, this
NSIndexPathwill help you identify precisely which section and which row. They are both integers. If you’re a beginner, I would say try with just one section.It is called if you implement the
UITableViewDataSourceprotocol in your view controller. A simpler way would be to add aUITableViewControllerclass. I strongly recommend this because it Apple has some code written for you to easily implement the functions that can describe a table. Anyway, if you choose to implement this protocol yourself, you need to create aUITableViewCellobject and return it for whatever row. Have a look at its class reference to understand re-usablity because the cells that are displayed in the table view are reused again and again(this is a very efficient design btw).As for when you have two table views, look at the method. The table view is passed to it, so you should not have a problem with respect to that.