transfer the variable from one ViewController to another
-
Please indicate how the variable value can be transferred from one ViewController's to another? I am now following: Cell compression process
tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath):
let appDelegate = UIApplication.sharedApplication().delegate! as! AppDelegate let TaskData: TaskListTableViewController = TaskListTableViewController() TaskData.catID = currentCell.categoryID!.text // В этом месте пытаюсь передать данные let initialViewController = self.storyboard!.instantiateViewControllerWithIdentifier("taskListTable")// as! UIViewController appDelegate.window?.rootViewController = initialViewController appDelegate.window?.makeKeyAndVisible()
В контроллере TaskListTableViewController переменная объявлена:
class TaskListTableViewController: UITableViewController, UIPageViewControllerDelegate { var catID: String?
//------------------------------
...
...
But in the performance of the catID, the nil returns.
Can you tell me what the problem is?
-
Better use
segue
:1 PKM from the counteraller to which we move to the controller:
2 Identifier
segue
:3 Redefined
prepareForSegue
As you wish.override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { let controller = segue.destinationViewController as! SecondVC //приводим `destinationViewController` к нужному нам `SecondVC` controller.s = "Woohoo" //s - строковая переменная, которой присваивем "Woohoo" }
4 at the required event.
performSegueWithIdentifier("SHOWVC", sender: self)