I am having trouble passing data (an image and two labels specifically) over from a table view controller to another controller. my goal is to make it so that when a user selects an option from the table view, it will go to the next controller and show the specific image and info for what option they selected. Is there a simple fix that I am just missing?
Asked
Active
Viewed 486 times
1 Answers
0
Create a variable at your destination controller of same type of the variable you want to pass, and use the did select method to navigate to the destination controller and passing the data like below :
func tableView(_ tableView: UITableView, didSelectRowA indexPath: IndexPath) {
let nextVC = DestinationVC()
nextVC.info = yourArray[indexPath.row].info
nextVC.modallyPresentingStyle = .fullscreen
self.present( nextVC, animated: true, completion: nil)
}
Pass all the data you want like info data, don't forget to create all variables at destination controller with same declaration type, for example if you want to pass an image then at your destination VC create an image variable like below
var selectedImage = UIImage()
And then add it to the previous method
nextVC.selectedImage = yourImage // if not part of a cell at index path
nextVC.selectedImage = yourArray[indexpath.row].yourImage // if it is related to specific cell at index path