Answer the question
In order to leave comments, you need to log in
How, when clicking on different cells of one UITableViewController, pass different information to another, common UITableViewController?
The situation is as follows: there are 2 UITableViewController. The first one has 10 cells and the second one is generic with 1 imageview and label. It is necessary that when you click on different cells of the first controller, different information is displayed in the second. It’s clear with the first one, various information can be passed through didSelectRowAtIndexPath, but how can it be connected to the imageview and label of the second UITableViewController?
import UIKit
class MainTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.estimatedRowHeight = 45.0
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print ("Selected row = \(indexPath.description)")
if indexPath.section == 0 && indexPath.row == 1 {
//передать текс в label CatTableViewController
}
}
}
Answer the question
In order to leave comments, you need to log in
In the 2nd controller, create a property in the header like Name (@property (strong, nonatomic) NSString * name;
When you click on a cell on the 1st controller, where you create the 2nd controller, refer to its property (mySecondVC.name = myDataArray[indexPath.row];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question