2014-03-28 51 views
-2

我有2個視圖控制器通過使用segue連接。如何將第二個視圖控制器中的一個字典{「fist」:1,「second」:2}傳遞給第一個視圖控制器。如何將字典從一個視圖控制器傳遞到另一個視圖控制器

+0

我建議通過讀取數百個答案,這個問題是此網站上已開始。如果他們不適合你,請解釋你的情況有什麼不同。 –

+0

在'prepareForSegue:'把它傳遞給堆棧通過一個協議。 – Abizern

+0

我是iOS新手,目標c ..我已經嘗試了一些可用的堆棧溢出解決方案。不幸的是我沒有得到輸出。如果你想幫助我,那麼我試圖得到別人的幫助來解決我的問題,否則只是忽略。 –

回答

0

您必須將標識符添加到故事板中的segue中。 在YOUT源視圖控制器覆蓋prepareForSegue:方法:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 
    if ([segue.identifier isEqualToString:@"YOURIDENTIFIER"]) { //<-YOURIDENTIFIER the same as you set up in storyboard 

     UIViewController *vc = (UIViewController*)segue.destinationViewController; 
     // You should cast destination view controller to your custom view controller sub class: 
     //YourViewController *vc = (YourViewController*)segue.destinationViewController; 
     // Pass the data 
     vc.myDictionary = @{{"fist":1,"second":2}; 
     // I assume you have property myDictionary in YourViewController class 
    } 
} 

希望這有助於

+0

謝謝灰色...它爲我工作。 –

+0

你能標記爲回答,所以也許別人會發現它有用。 – Greg

相關問題