ios - 从 View Controller 过渡到选项卡栏 Controller ,并在每个选项卡错误处使用导航 Controller

标签 ios uinavigationcontroller uitabbarcontroller segue

您好,我添加了准备转场代码以传输信息,但是我收到错误。

我有一个标签栏 Controller 。它有 4 个选项卡。每个选项卡都有一个导航 Controller 和一个 VC 作为 Root View Controller 。

从选项卡 1--> 导航 Controller --> VC 1 我需要为选项卡 2--> 导航 Controller ---> VC1 取一个值

(也是连接到选项卡 2 处导航 Controller 的 Segue,或者选项卡 2 处的 Root View ) 预先感谢您

错误:customizedViewControllers]:无法识别的选择器发送到实例 0xf19bd60 (但我要选择选项卡 2(索引 1))? 我的错误在哪里?

    if ([segue.identifier isEqualToString:@"ResultsSegue"])

        {
//the root VC at tab 2
            ResultsIndexViewController*controller=[[ResultsIndexViewController alloc]init];

            UITabBarController *tabController = [segue destinationViewController];
            controller = (ResultsIndexViewController*)[[tabController customizableViewControllers]objectAtIndex:1];//crashing here
            controller.resultsArray=[NSMutableArray arrayWithArray:_matchedResultsArray];

        }
    }

最佳答案

这部分代码

 [1]   UITabBarController *tabController = [segue destinationViewController];
 [2]    controller = (ResultsIndexViewController*)[[tabController customizableViewControllers]objectAtIndex:1];//crashing here

充满了误解。

在[1]中,您将destinationViewController(类型UIViewController)分配给类型UITabBarController的对象。这是编译器合法的(UITabBarController 继承自 UIViewController,因此它们都是 UIViewController 类型),但它并不能真正反射(reflect)正在发生的情况。您的转场将是 UIViewController 或它的 UINavigationController

因此,在第 [2] 行中,当您尝试使用 tabController 作为选项卡栏 Controller 时,它会崩溃(因为它不是一个)。

您需要重新设计您的项目...忘记 Segue,并使用选项卡栏 Controller 。类似...

- (IBAction)moveToTab2:(id)sender {
    ResultsViewController* resultsVC = (ResultsViewController*)
                [[self.tabBarController viewControllers] objectAtIndex:1];
    resultsVC.resultsArray=
                [NSMutableArray arrayWithArray:_matchedResultsArray];
    [self.tabBarController setSelectedViewController:resultsVC;
}

关于ios - 从 View Controller 过渡到选项卡栏 Controller ,并在每个选项卡错误处使用导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14259639/

相关文章:

swift - 通过推送在 View 中隐藏标签栏

ios - 如何在单击 iOS 的自定义选项卡栏按钮上弹出到 Root View Controller

ios - 多色标签栏图标

iphone - 在 UITabBarController 中的 UIViewController 之间共享 UIView

ios - Flutter - 如何创建 CupertinoAlertDialog

ios - 导航 Controller 中不允许使用 UINavigationControllers

ios - 应用内购买在模拟器上更改测试用户

ios - 在自定义 UINavigationBar 中绘图,附加到顶部

ios - 如何检查哪些文件存储在 iCloud 上?

iOS:使用 UIImage 在 collectionview reoloaddata 中崩溃