I am pretty new to Iphone development . so please bear me if I ask some very simple questions.
In my application I have multiple views(i.e. .xib files). On clicking
I've encounter some similar problem there. The table view delegate and data source is set properly, and (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
also returns a positive count. But - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
is never called.
I've tried the methods before, but It doesn't work neither. Finally, I've noticed that I've forgotten to add the table view as a subview of my view controller. After doing that, it works like a charm.
Initialize UITableView in viewWillAppear...
For anyone that comes across this problem, I solved this by adding my TableView's controller as a child to the parent controller using:
UITableViewController * table = [[UITableViewController alloc] init];
...
[self.view addSubview:table.tableView];
[self addChildViewController:table];
Old question, but I'll chime in. For others.
There are a number of reasons why a tableview doesn't update and that cellForRowAtIndexPath: doesn't get called.
If you're using a UITableViewController directly then it amy be that the "numberOfRowsInSection:" method is returning 0
If you're using a UItableView in your view controller. chances are you haven't adopted the correct protocols and implemented the right methods - plus if you're using a xib or storyboard that you haven't assigned the right delegate and datasource is the other potential problem.
Finally if you're using a subclass of UITableViewController then it's possible that you haven't overwritten one of the default methods and again numberOfRowsInSection is returning 0.
If the mutable array or the array you are using to populate the contents of the cell is set as a property in your header file. then make sure you always use
self.yourArray = [[NSMutableArray alloc] init];
[self.yourArray addObject:@"Object1"];
and then to get the count in numberOfRowsInSection as well you need to access it as:
return [self.yourArray count];
This is pretty much like the this pointer you use to refer to your instance variables. And yes of course you also need to keep in mind if you have set the dataSource and delegate of the UITableView to the file's owner. Also that you have included the UITableViewDelegate and UITableViewDataSource in your header file of the viewController.
I hope it helps you. Best Of Luck. Happy Coding! Cheers!!
I was also having that problem on UITableView, I also set the data source and delegate to the table view but my cellForRowAtIndexPath
method was not called.
Solution:
my network blocked my method (by using firewall). I asked my network admin, and I was given full access to the network, and then my cellForRowIndexPath
method was called.
when my response comes from a web service, due to network block response was black so, cellForRowIndexPath
method was not called.