0
votes

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.

1
I'd look into using delegates to update the model from the cell implementations, rather than trying to call 'down' to cell implementations. - Chris Shaw
Sounds like u are creating a form to capture user inputs. You might want to consider using Eureka, its a pretty good form library. - Koh
@Koh I have already created my custom tableview cells. I just need to extract the user input from all the cells but they get dequeued as you scroll down, so my main concern now is to get the user input from each cell - btrballin

1 Answers

2
votes

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.