2013-06-27 65 views
0

我有一個UITabBarController加載2 UIViewControllers:地圖和表。當單擊tabBarItem,我趕上事件,並在目標視圖中的某些屬性:UITabBarController和UIViewController轉換

- (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 
{ 
    if([viewController.tabBarItem.title isEqualToString:@"Map"]) { 
     MapViewController *MVC = [tabBarController.childViewControllers objectAtIndex: viewController.tabBarController.selectedIndex]; 
     MVC.billboards = self.billboards; 
     MVC.rangeMaxWidth = self.rangeMaxWidth; 
     MVC.rangeMaxHeight = self.rangeMaxHeight; 
     MVC.APIRoot = self.APIRoot; 
    } 
} 

現在上面的代碼的偉大工程;然而,當我嘗試爲我的表格視圖做同樣的事情時,我得到一個神祕的錯誤。下面是全碼:

- (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 
{ 
    if([viewController.tabBarItem.title isEqualToString:@"Map"]) { 
     MapViewController *MVC = [tabBarController.childViewControllers objectAtIndex: viewController.tabBarController.selectedIndex]; 
     MVC.billboards = self.billboards; 
     MVC.rangeMaxWidth = self.rangeMaxWidth; 
     MVC.rangeMaxHeight = self.rangeMaxHeight; 
     MVC.APIRoot = self.APIRoot; 

    } else if ([viewController.tabBarItem.title isEqualToString:@"Manage"]) { 

     ManageBillboardsController *MBC = [tabBarController.childViewControllers objectAtIndex: viewController.tabBarController.selectedIndex]; 

     MBC.aNumber = [[NSNumber alloc] initWithInt:3]; 
    } 
} 

- [UINavigationController的setANumber:]:無法識別的選擇發送到實例0x9e91400 2013年6月27日15:09:18.624廣告牌[3269:C07] *終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,原因:' - [UINavigationController setANumber:]:無法識別的選擇器發送到實例0x9e91400'

我想我已經雙重檢查了一切,兩個視圖似乎都一樣。所以我不明白爲什麼這適用於地圖視圖,但不適用於表格。

在此先感謝。

*解*

- (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 
{ 
    if([viewController.tabBarItem.title isEqualToString:@"Map"]) { 
     MapViewController *MVC = [tabBarController.childViewControllers objectAtIndex: viewController.tabBarController.selectedIndex]; 
     MVC.billboards = self.billboards; 
     MVC.rangeMaxWidth = self.rangeMaxWidth; 
     MVC.rangeMaxHeight = self.rangeMaxHeight; 
     MVC.APIRoot = self.APIRoot; 

    } else if ([viewController.tabBarItem.title isEqualToString:@"Manage"]) { 
     UINavigationController *NC = [tabBarController.childViewControllers objectAtIndex: viewController.tabBarController.selectedIndex]; 
     NSArray *controllers = [NC childViewControllers]; 

     for(id item in controllers){ 
      ManageBillboardsController *MBC = item; 
      MBC.aNumber = [[NSNumber alloc] initWithInt:3]; 
     } 
    } 
} 

回答

1

好像你的表視圖是一個UINavigationController內。所以MBC應該UINavigationController類型,然後讓你的表視圖(如果它的頂部),像這樣:

MBC.topViewController 

然後在其上設置aNumber

+0

嗯我認爲你是正確的,但我沒有明確定義這個導航控制器在任何地方,即:.h文件中沒有變量。我應該從哪裏開始尋找? –

+0

您的故事板或XIB? – Danilo

+0

好的你的建議讓我走上正確的道路。我將在此主題中添加一篇文章,展示解決方案。謝謝! –

相關問題