簡體   English   中英

Segue無法從標簽欄控制器中的ViewController運行

[英]Segue not working from the viewcontroller inside tabbar controller

我創建了一個標簽欄應用程序。 根視圖是帶有導航控制器的標簽欄。 當我嘗試從標簽欄的初始視圖控制器觸發segue時,它無法正常工作並在控制台中引發錯誤

“由於未捕獲的異常'NSInvalidArgumentException'而終止應用程序,原因:'Receiver()沒有標識符為'series'的segue”

    Tabbar Code in appdelegate:

        self.tabBarController = [[UITabBarController alloc] init];
        self.tabBarController.tabBar.barTintColor = [UIColor blackColor];
        self.tabBarController.tabBar.tintColor = [UIColor redColor];

        HomeViewController *VC1 = [[HomeViewController alloc] init];
        VC1.title = @"Home";
        UINavigationController *VC1Navigation = [[UINavigationController alloc]
                                                 initWithRootViewController:VC1];
        wishListViewController *VC2 = [[wishListViewController alloc] init];
        VC2.title = @"My list";
        UINavigationController *VC2Navigation = [[UINavigationController alloc]
                                                 initWithRootViewController:VC2];
        SearchBarVC *vc3 = [[SearchBarVC alloc] init];
        vc3.title = @"Search";
        UINavigationController *VC3Navigation = [[UINavigationController alloc]
                                                 initWithRootViewController:vc3];

        ProfileViewController *vc4 = [[ProfileViewController alloc] init];
        vc4.title = @"More";
        UINavigationController *VC4Navigation = [[UINavigationController alloc]
                                                 initWithRootViewController:vc4];

        NSArray* controllers = [NSArray arrayWithObjects:VC1Navigation, VC2Navigation,VC3Navigation, VC4Navigation, nil];
        self.tabBarController.viewControllers = controllers;

        [[self.tabBarController.tabBar.items objectAtIndex:0] setImage:[UIImage imageNamed:@"homes.png"]];
        [[self.tabBarController.tabBar.items objectAtIndex:1] setImage:[UIImage imageNamed:@"wishlist.png"]];
        [[self.tabBarController.tabBar.items objectAtIndex:2] setImage:[UIImage imageNamed:@"searchs.png"]];
        [[self.tabBarController.tabBar.items objectAtIndex:3] setImage:[UIImage imageNamed:@"dots.png"]];

        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        self.window.backgroundColor = [UIColor whiteColor];
        self.window.rootViewController = self.tabBarController;
        [self.window makeKeyAndVisible];


Segue

[self performSegueWithIdentifier:@"Nav2SingleVid" sender:self];

請檢查是否觸發了segue:

1,通過用戶手勢如果手勢是從手勢識別器或可輕擊的視圖發出的,則它將變成動作手勢,這意味着它將在發生輕擊或其他手勢時自動觸發。 您的源視圖控制器類可以防止觸發動作序列。 為此,請重寫此方法:shouldPerformSegue(withIdentifier:sender :) 2,在代碼中performPergue(withIdentifier:sender :)

此方法的默認實現不執行任何操作。 您可以基於segue的上下文覆蓋它,以將相關數據傳遞到新的視圖控制器或窗口控制器。 segue對象描述過渡,並包括對segue中涉及的兩個控制器的引用。

Segues可以從多個來源觸發,因此請使用segue和sender參數中的信息來消除應用程序中不同邏輯路徑之間的歧義。 例如,如果segue源自表視圖,則sender參數將標識用戶單擊的單元格。 您可以使用該信息在目標視圖控制器上設置數據。

暫無
暫無

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

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