简体   繁体   中英

How to capture cell data from UITableView with multiple cell prototypes?

I designed a UITableView containing 3 different cell prototypes. I'm trying to figure out how I can capture their user inputs. One of them has a checklist in the form of a nested table view, so I need the ones they selected. Another has a UIPickerView so I need the selected option from a PickerView. Last one is a text area so I need the string inputting in that.

So I not only need a mechanism to capture the data to repopulate it back with their inputs when the user scrolls up or down to make it visible again. Would the best option be to use the following delegate function to capture non-visible cells:

func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    // do something with the cell before it gets deallocated
}

and then capture data on the visible cells on form submission? I'm not sure if this approach would work, so I'm wondering if there are better options.

The form input data would be 1 to many sections of self-repeating cells for sections 2 and up, so I need a way to capture all the input data with the TableView dequeuing these cells.

Your approach is wrong.

You have to implement a logic to update the data model at the moment the user changes something in the view .

This can be accomplished with protocol / delegate or with callback closures.

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