簡體   English   中英

UITabBarController和UIViewController過渡

[英]UITabBarController and UIViewController Transition

我有一個UITabBarController,它加載2個UIViewControllers:一個映射和一個表。 單擊tabBarItem時,我捕獲了事件並在目標視圖上設置了一些屬性:

- (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-06-27 15:09:18.624 Billboard [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];
        }
    }
}

好像您的表格視圖在UINavigationController內部。 因此, MBC應該是UINavigationController類型,然后像下面這樣獲取您的表視圖(如果位於頂部):

MBC.topViewController

然后設置aNumber就可以了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM