Thursday 30 May 2013

Handling CellForRowAtIndexPath Method not calling

Hi All,

In my application I used multiple  tableViews for eg: two. For the first table all delegate and datasource methods are called. When I add the second table and call the method
[self.tableView reloadData];
cellForRowAtIndex method is not called. In the second table, the number of sections is 1 and the number of rows is 5. I set the delegate and datasource for tableView programatically.

add the following asserts to your code (before the call to reloadData) and see what happens: NSAssert(self.tableView, @"No tableview"); NSAssert(self.tableView.dataSource, @"No datasource")

When NSAssert(self.tableView.dataSource, @"No datasource"); is crashing, you haven't set the dataSource of the tableView correctly.
The NSAssert will crash your app if the condition inside the parenthesis of the assert validates to false (or 0, or in this case nil).
Wherever you create your tableView, make sure that you set the dataSource (and probably delegate too) correctly.
Regarding setting the dataSource correctly, don't make the mistake to set the dataSource to a newly created instance of your viewController. Most likely you want to use self.tableView.dataSource = self;.


Solution:

If you are maintaing a multiple views & mulitple tableviews in single view controller, some times CellForRowAtIndexPath Method(DataSource Method) is not calling.


We can handle this by taking another view controller displaying the same class.

No comments:

Post a Comment