TableView Edit Button Rows Display

Hello! This is unfortunately a very amateur question but my team and I are building an app in XCode with Swift, and we are having difficulties trying to display both checked and unchecked ingredients when the edit button is pressed in the corner. If this is a confusing description, we are basically trying to mimic the activity of the edit button in the Mail app on the Mailboxes TableView: You press it, and it pops up both the inboxes you have checked off, as well as ones you do not have checked off. Any advice on how to implement this? It would be greatly appreciated!


Carl

It looks like Mail is putting a UITableView into "editing" mode, where the cells display differently. Look here:


https://developer.apple.com/documentation/uikit/uitableview/1614876-setediting


and here:


https://developer.apple.com/documentation/uikit/uitableviewcell


In particular, look at the UITableViewCell methods that have "editing" in their names, such as "editingAccessoryType".

Thank you for the documentation! However, we are just learning Swift and don't really understand the API you provided. Do you have any suggestions on what function or combination of functions are necessary in order to

1. Check whether a cell is selected or unselected

2. Display selected cells while not displaying unselected cells

We figured out that you can set the height of a cell to 0 in order to "remove" it from the TableView, but beyond that, we are lost.

Thank you!

I don't have any specific suggestions, because there are probably several "pieces" to solve this.


1. You shouldn't approach this be trying to find out what's selected by asking cells. Instead, you should keep a data model with an entry for each item (for each row, that is), which says whether that row ought to be selected/unselected when displayed in editing mode, or ought to be shown/hidden in normal mode.


2. You will probably need to detect when the table enters editing mode (via the action on the Edit button). At that point, you can insert additional rows into the table for the unselected cells. When the table exits editing mode, you can remove the unselected rows.


I would suggest you look around for sample code that does something similar, so you can study the various techniques that might be used.

See Sample Code - search on: table

TableView Edit Button Rows Display
 
 
Q