简体   繁体   中英

Pattern for no data in a section in collectionView/TableView

I am contemplating on what is the recommended way to display a notice that there is no data for a specific section in a collectionView/TableView

One way is to create a special cell and to put that in instead of the data cells. That feels odd, since the "empty notice" cell doesn't correlate with the data, which means I would need to spread a lot of conditions in didSelectItem, configuring the cell, etc

Using https://github.com/dzenbot/DZNEmptyDataSet is appropriate only when the entire view is empty, not in a specific section

Another way would be (which is what I do now) to insert a UIView into the place where the data would be as a subview of the collectionview, But this also would require maintenance when reloading the data, scrolling, tapping. Also this requires calculation of where to place the view, which means I need to change it per collectionview, since it is not part of the collectionviewlayout

Is there a recommended pattern to deal with these situations?

Maybe you shouldn't have that section at all if the section contains empty data. Reduce section count by 1 at - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView datasource method and recheck the cell to be displayed during - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath datasource method.

In reply to you, I think you would have some type of "Add" button to add comments, photos, friends, etc. Make the option to add a comment or photo less obtrusive than taking an entire tableView row, and omit the comment or photo section, if there are no comments or photos.

If you put an "Add comment" or "Add photo" row while displaying details, users will likely get tired of unnecessarily reading that, as they use the app.

Note that tableViews generally handle insertion in editing mode , and when not editing, no section is shown if it is empty .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM