Reputation: 3885
In my code, some cells should not be shown to the user on the UITableView.
So my dataSource would supply objects, but I'd like to check in my cellForRowAtIndexPaht
if the cell is hidden, and if it is, practically return nothing.
So that the cell's height would be zero, but more than that, I'd like to save my function the building of the whole cell.
I tried to return nil, but alas, it crashes.
Upvotes: 1
Views: 390
Reputation: 14656
Could you move the logic up into the numberOfSections
or numberOfRowsInSection
methods used to create your UITableView? Basically, whatever logic you are using to try and return null for those cells could move into the numberOfRowsInSection
method in the UITableView class and return only the number of visible (not hidden) cells.
Then you would have to configure your cellForRowAtIndexPath
method to hand out the cells from your data source in order by counting up through your visible rows instead of just pulling them out the array.
I wouldn't think you would want to return 'nothing' to a program expecting an object.
Link to Apple Reference Docs for UITableView, the numberOfSections and numberOfRowsInSections can easily be used to logically modify the amount of data being shown in a table view.
Upvotes: 1
Reputation: 75058
The data source is supposed to return what is actually in the table.
You can easily make a new array to hold the data you want shown, and omit the data you do not want to see (keeping it in a master data source). Then as some rows in the table view are able to be seen, add them into the array of table data and use the insertRows method of UITableView to animate viewing the newly unveiled data.
Upvotes: 2