2014-02-06 183 views
-1

我有2個視圖控制器的第一個是uinavigationcontroller的根。 在該視圖控制器(第一)我有nsmutable數組,包含我創建的自定義類。到現在爲止還挺好 :)。從根視圖控制器傳遞NSMutableArray到推視圖控制器

現在在第二個視圖控制器(第一個孩子)還有另一個nsmutable陣列 ,我想從第一個視圖控制器(從根)傳遞給他的數組。

所以在該方法中:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 

我使用此代碼:

if([segue.identifier isEqualToString:@"showDetailSegue"]){ 
     UINavigationController *navController = (UINavigationController *)segue.destinationViewController; 
     tableViewController *controller = (tableViewController *)navController.topViewController; 
     controller.monthnames = monthnames; 
    } 

但是當我運行該程序,並執行SEGUE我得到這個錯誤消息:

[tableViewController topViewController]: unrecognized selector sent to instance 0x9836f20 

我在做什麼錯了?

感謝所有傭工:)

+1

請搜索很多答案已經在這個論壇上 –

+0

是啊這就是我做了我最後2小時 –

回答

0

segue.destinationViewController已經是你的第二個視圖控制器 (而不是導航控制器):

if([segue.identifier isEqualToString:@"showDetailSegue"]){ 
    tableViewController *controller = (tableViewController *)segue.destinationViewController; 
    controller.monthnames = monthnames; 
} 
+0

非常感謝它的工作:) –

0

我相信你SEGUE點表視圖控制器不是導航控制器。將您的代碼替換爲:

if([segue.identifier isEqualToString:@"showDetailSegue"]){ 
     tableViewController *controller = (tableViewController *)segue.destinationViewController; 
     controller.monthnames = monthnames; 
    } 

它應該有所幫助。

相關問題