0

当点击 ViewController A 中的按钮时,TableViewController B 会出现。用户在 B 中选择了一个项目,然后被引导回 A。我使用以下代码从 B 返回 A。但是如何将所选项目传递([Int: String])给 A?

navigationController?.popViewControllerAnimated(true)

下面是从 A 导航到 B 的代码

 let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

 let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("categories") as! CategoryListViewController

 self.presentViewController(nextViewController, animated:true, completion:nil)
4

1 回答 1

1

在您的班级中创建一个像这样 ViewController A的空 Dictionary

var dict = [Int: String]()    

现在,当您将TableViewController BViewController A设置为dict这样 时

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

 let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("categories") as! CategoryListViewController

// here you pass parameter to ViewController A

nextViewController.dict =  YourVaribleWhichStrore[Int:String] 

 self.presentViewController(nextViewController, animated:true, completion:nil)
于 2015-06-20T05:32:07.583 回答