Thing I want to do

When you press the button on the navigation bar
Get the value of each cell in tableView (label, textView, etc.)
I want to pass it to the transition destination.
* For the cell, the one generated by the xib file is read by tableView.


I knew how to pass the value of a cell to the transition destination when I tapped it.
I didn't know how to get all the values.
I don't have the code for that part because I couldn't figure out how to do it ...
Excuse me...
I wondered if I could put the for in the array by turning it by the number of cells.
I couldn't think of a concrete way to write it.
I would appreciate it if anyone could tell me.
Thank you.


Xcode: 11.1

  • Answer # 1

    Please pass all the required sequences.

    var items = ["A", "B", "C"]
    func tableView (_ tableView: UITableView, numberOfRowsInSection section: Int)->Int {
        return items.count //<-If it looks like this, pass this items to the transition destination

    Is it like this to select/deselect all the displayed cells?

    // Processing when tapping the select all/deselect all button
    @IBAction func btnDidTap (_ sender: UIButton) {
        switch sender.isSelected {
        case true:
            items.enumerated (). forEach {
        TableView.deselectRow (at: IndexPath (row: $0.offset, section: 0), animated: true)
        case false:
            items.enumerated (). forEach {
                tableView.selectRow (at: IndexPath (row: $0.offset, section: 0), animated: true, scrollPosition: .none)
        sender.isSelected.toggle ()

    I came up with it when I wrote ittableView.allowsMultipleSelection = trueIf you set (multiple selections are possible) and extract the corresponding value->pass by value, you do not need to take any special action after selecting all.

Related articles