iOS SplitView控制器,以多个故事板以编程方式更改视图

时间:2013-11-07 14:53:11

标签: ios storyboard uisplitviewcontroller ipad

希望有人可以提供帮助。

我有一个使用UISplitViewController的应用,但我现在不得不开始使用多个storyboards,因为我有大量views并且Xcode正在启动跑得很慢。我已移动UIViewControllers移动到多个storyboards

Master View是由静态单元格构建的,因此当用户选择单元格时,我通常会通过推送view来更改segue

我现在想知道如何以编程方式更改UISplitViewController的详细信息视图?

由于

1 个答案:

答案 0 :(得分:4)

子类UISplitViewController并将您的根splitViewController设置为该类。然后将此方法添加到UISplitViewController子类:

-(void)setDetailControllerTo:(UIViewController *)detailController withNavControllerTitle:(NSString *)title {
    [detailController view]; // this line forces the viewDidLoad method to be called

    if (title) {
        UINavigationController *navController = [[UINavigationController alloc] init];
        [navController pushViewController:detailController animated:YES];
        detailController.title = title;

        NSArray *viewControllers=@[self.mainController.viewControllers[0],navController];
        self.mainController.viewControllers = viewControllers;
    } else {
        NSArray *viewControllers=@[self.mainController.viewControllers[0],detailController];
        self.mainController.viewControllers = viewControllers;
    }
}

要调用此方法,请从主视图控制器执行以下操作:

FixedSplitViewController *splitController = (FixedSplitViewController*) self.splitViewController;

CurrentEventViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"CurrentEventViewController"];
// add any setup code here
[splitController setDetailControllerTo:controller withNavControllerTitle:@"Current Event"];

我的很多项目都要求splitviewcontroller始终显示主视图,所以我使用这个子类来保持主视图不会隐藏在纵向旋转上。