2015-06-20 72 views
0

當ViewController A中的按鈕被點擊時,TableViewController B顯示出來。用戶在B中選擇一個項目,然後返回到A.我使用下面的代碼從B返回A.但是,如何將所選項目([Int: String])傳遞給A?如何使用swift中的參數返回之前的視圖控制器

navigationController?.popViewControllerAnimated(true) 

下面是代碼從A

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

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

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

回答

1

,當您移動從TableViewController BViewController A集導航到B在你ViewController A類中創建一個空的Dictionary這樣

var dict = [Int: String]()  

現在值爲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) 
+0

如果您需要任何幫助,請告訴我? –

相關問題