Why isn't cellForRowAtIndexPath fired but other methods are? - ios

numberOfSectionsInTableView and numberOfRowsInSection are both called on my table. The array I'm using has 3 items in it.
cellForRowAtIndexPath is never called. What would cause this behavior?

Might be something to do with the dimensions of your tableView. See this other answer for details. Basically, what is says is that if your tableView is too small, then the cellForRowAtIndexPath method is never called. Try making your tableView smaller, or decreasing the size of your header or footer of the tableView. If this doesn't work, try reloading the table using tableView.reloadData() on the main thread.

Related

cellForRowAtIndexPath is being called for non visible cells also

tableview data source method cellForRowAtIndexPath is being called for the non visible rows also which is creating a problem in pagination in tableview. Did anyone face this issue?
The system calls this method to prepare cells ahead of time, so scrolling is smoother and more responsive. If you want to fetch more data as the user scrolls down/up you should rather implement UITableViewDelegate method tableView(_:willDisplay:forRowAt:) - this method is called just before the cell is displayed to the user.

In UITableView, what's the delegate for "visibleCells"?

When cells come in and out of device's screen, I want my viewController to know exactly what came and what went out. Is there a way to do this?
There isn't a delegate method just for "visible cells". There isn't anything called when a cell leaves the screen. There really isn't anything when a cell becomes visible.
There is the cellForRowAtIndexPath data source method. This is called when a cell is needed.
There is the willDisplayRowAtIndexPath delegate method. This is called when a cell will be displayed.
There is the didEndDisplayingCell delegate method. This is called when a cell is removed from the table view.
There is the indexPathsForVisibleRows method on UITableView. This lets you know what rows are currently in view.
There is the prepareForReuse method on UITableViewCell. This lets a cell reset itself to be reused for another row.
Better describe what you are trying to accomplish in order to get a more specific answer.

numberOfRowsInSection returns more than 0; cellForRowAtIndexPath still not being called

I notice this problem is very common and there are alot of posts about it but none of the solutions i tried so far worked.
So I have a delegate method that updates the datasource: NSArray * posts and reload the table view. I am positive that posts is updated before the reload call because i logged it.
It calls the numberOfRowInSection method and [posts count] returns more than 0 every time. but the cellForRowAtIndexPath is still not called.
the tableview is created from the IB and content is currently shows content and the cells before the reload. i need one of the cells content to be updated but it doesnt because cellForRowAtIndexPath is not called.
This only happens for the delegate method.
I tried making the reload call on the main thread using both gcd and perform selectorOnMainThread still no go.
Any ideas what maybe causing this problem and how to fix it?
Make sure you have UITableViewDataSource, UITableViewDelegate in your .h and connected the tableview delegate, data source and cellindentifier Cell in .xib.
have you registered your cell ?
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:#"Cell"];
Load your tableView in method
awakeFromNib
this solved my problem.

UITableView reloadData and cellForRowAtIndexPath - interruptable?

Let's assume there exists a UITableView called myTable. Let's say the following sequence of events occur --
Table is fully populated.
The data source is updated (in this case an sqlite3 db, but doesn't really matter), an NSNotifcation happens to indicate that there is new data, the main thread receives the notification and then calls [myTable reloadData].
myTable's UITableViewDataSource's numberOfSectionsInTableView gets called. Assume only 1 section.
myTable's UITableViewDataSource's tableView:numberOfRowsInSection: gets called.
Several tableView:cellForRowAtIndexPath:'s get called depending on the number of rows in the data source.
My question has to do with the interruptability of cellForRowAtIndexPath.
The question --
If a "reloadData" is called and cellForRowAtIndexPath's are getting called AND another reloadData comes in, will the cellForRowAtIndexPath's stop midstream and restart after the calls to numberOfSectionsInTableView and numberofRowsInSection?
Or will the new reloadData be queued, such that all of the cellForRowAtIndexPaths will finish BEFORE the numberOfSectionsInTableView and numberOfRowsInSection get called?
I've looked and have been unsuccessful in finding an answer to this question in docs or the net. I'm concerned that if the data store is updated while the cellForRowAtIndexPaths are "running", the numberOfSectionsInTableView can change which can result in the cellForRowAtIndexPath requesting data for a cell that's now out of range.
Any help would be greatly appreciated.
Since you should only call reloadData on the main thread and since by the time a call to reloadData is done, all of the visible cells have already been loaded, there is no problem to worry about. The second call to reloadData will be made after the 1st one is done.
I don't think it is possible to be in the middle of cellForRowAtIndexPath when reloadData is called assuming they are both called on the same (main) thread (having an async processing on background thread at cellForRowAtIndexPath seems meaningless).

tableview data source method is not getting called in navigation based application

In my app control goes to numberOfSectionsInTableView and numberOfRowsInSection datasource methods but not to cellForRowAtIndexPath.
I am not able to find the problem,please any body give a solution for this.
Thanks in advance

Resources