Reputation: 81
I am making an app in which I have to pass the data of the table view cell the user clicks and also the data of the second table view cell.
I am able to pass the data of the current table view cell by using:
let Level2 = self.storyboard!.instantiateViewController(withIdentifier: "ReportVC") as? ReportVC {
Level2.passedRes = item.patient
Level2.passedRoom = item.room
Level2.passResImg = item.resImage
Level2.selectedBeacon = beac
self.show(Level2, sender: nil)
Also if no table view cell exists after that, I just want to pass no more table view cell's exist.
Upvotes: 0
Views: 80
Reputation: 67
The best thing You can do there is in
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
you choose the images or text or data that You want to pass to second VC (if you want to choose two indexPaths just add +1 on the second one(indexPath + 1)) and store it on UserDefaults. And then in 2nd VC You can retrieve it from UserDefaults. I hope this answer helped You!
Upvotes: 2
Reputation: 434
To get items from your datasource you could use dataSource[indexPath.row]
, indexPath you could get from the func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
. To get next item you need to check if it is not last (indexPath.row < dataSource.count - 1), if not just increment current indexPath.
Upvotes: 0