简体   繁体   English

iOS - 带故事板的UISplitViewController - 多个主视图和多个详细视图

[英]iOS - UISplitViewController with storyboard - multiple master views and multiple detail views

I'm trying to put together an iPad app using UISplitViewController and storyboards. 我正在尝试使用UISplitViewController和故事板组装一个iPad应用程序。 The master view starts with a navigation controller linked to a table view of 6 menu options. 主视图以链接到6个菜单选项的表视图的导航控制器开始。 Each cell in the table pushes a different table view controller onto the navigation stack. 表中的每个单元格将不同的表视图控制器推送到导航堆栈。 This is working fine for the master view. 这适用于主视图。 Each master view has a table list which when clicked needs to display a different view controller in the detail pane. 每个主视图都有一个表列表,单击该列表时需要在详细信息窗格中显示不同的视图控制器。 I've currently done this with a segue set to 'Replace' and 'Detail Split' which works the first time a row is clicked, but as soon as you click another row in the master view, or rotate the device then the app crashes with EXC_BAD_ACCESS. 我目前使用设置为“替换”和“细节拆分”的segue完成此操作,该设置在第一次单击一行时有效,但只要您在主视图中单击另一行,或者旋转设备,该应用程序就会崩溃使用EXC_BAD_ACCESS。

I'm fairly sure my problems are to do with how the delegate is setup for the UISplitViewController. 我很确定我的问题与如何为UISplitViewController设置委托有关。 I'm confused as to how this should be used when I have multiple master VCs and multiple detail VCs. 当我有多个主VC和多个细节VC时,我很困惑如何使用它。 Where should the delegate code be placed - master or detail? 代理代码应该放在哪里 - 主人或详细信息? Do I have to implement the UISplitViewControllerDelegate protocol events in every view controller? 我是否必须在每个视图控制器中实现UISplitViewControllerDelegate协议事件?

Any help appreciated. 任何帮助赞赏。

If the split view controller delegate was the detail view controller that had been replaced, this is the cause of the crash. 如果拆分视图控制器委托是已替换的详细视图控制器,则这是导致崩溃的原因。 The replaced detail view controller is being dealloc'd and so the split view controller delegate is no longer a reference to a valid object. 替换的详细视图控制器正在被解除分配,因此拆分视图控制器委托不再是对有效对象的引用。

You can update the delegate in prepareForSegue:sender:. 您可以在prepareForSegue:sender:中更新委托。 For example: 例如:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"MySegue"]) {
        UIViewController *destinationViewController = [segue destinationViewController];
        if ([destinationViewController conformsToProtocol:@protocol(UISplitViewControllerDelegate)]) {
            self.splitViewController.delegate = destinationViewController;
        }
        else {
            self.splitViewController.delegate = nil;
        }
    }
}

Which view controllers you use for delegates is dependent on your view controller hierarchy. 您用于代理的视图控制器取决于您的视图控制器层次结构。 In the simplest case, any view controllers that are assigned to splitVC detail will probably need to be delegates. 在最简单的情况下,分配给splitVC详细信息的任何视图控制器可能都需要是委托。 You may want to base them all on a common super class that handles the shared split view controller delegate logic. 您可能希望将它们全部基于处理共享拆分视图控制器委托逻辑的公共超类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS-情节提要中的UISplitViewController-多个主视图和多个详细视图 - iOS - UISplitViewController in storyboard - multiple master views and multiple detail views UISplitViewController多个详细信息视图分段控件 - UISplitViewController Multiple Detail Views Segmented Control UISplitViewController在按钮上单击主视图后可推送多个详细视图iPad - UISplitViewController push multiple detail views iPad upon button click on master view 如何在UISplitViewController的细节和主视图控制器之间刷新视图? - How to make the views refresh between detail & master view controllers of UISplitViewController? Storyboard 转到多个视图? - Storyboard Segue to Multiple Views? 如何在主从应用程序中呈现多个表视图? - How to present multiple table views in a Master-Detail application? 在TableView中使用多个详细信息视图 - Using multiple detail views with TableView 使用Xcode故事板创建主-主视图,其中“主视图”视图是“标签栏”到三个不同的视图 - Using Xcode Storyboard to create Master-Detail views where the Detail view is Tab Bar to three different views 如何在标题视图iOS中创建情节提要布局多个视图? - How to create storyboard layout multiple views within header view iOS? iOS中的多个警报视图 - Multiple Alert Views in iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM