iOS - 带故事板的UISplitViewController - 多个主视图和多个详细视图 [英] iOS - UISplitViewController with storyboard - multiple master views and multiple detail views

查看:85
本文介绍了iOS - 带故事板的UISplitViewController - 多个主视图和多个详细视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用UISplitViewController和故事板组合一个iPad应用程序。主视图以链接到6个菜单选项的表视图的导航控制器开始。表中的每个单元格将不同的表视图控制器推送到导航堆栈。这适用于主视图。每个主视图都有一个表列表,单击该列表时需要在详细信息窗格中显示不同的视图控制器。我目前使用设置为'替换'和'细节拆分'的segue完成此操作,该设置在第一次单击一行时有效,但是只要您在主视图中单击另一行,或者旋转设备,然后应用程序崩溃使用EXC_BAD_ACCESS。

I'm trying to put together an iPad app using UISplitViewController and storyboards. The master view starts with a navigation controller linked to a table view of 6 menu options. 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.

我很确定我的问题与如何为UISplitViewController设置委托有关。当我有多个主VC和多个细节VC时,我很困惑如何使用它。代理代码应该放在哪里 - 主人或详细信息?我是否必须在每个视图控制器中实现UISplitViewControllerDelegate协议事件?

I'm fairly sure my problems are to do with how the delegate is setup for the UISplitViewController. I'm confused as to how this should be used when I have multiple master VCs and multiple detail VCs. Where should the delegate code be placed - master or detail? Do I have to implement the UISplitViewControllerDelegate protocol events in every view controller?

任何帮助表示感谢。

推荐答案

如果拆分视图控制器委托是已替换的详细视图控制器,则这是导致崩溃的原因。替换的详细视图控制器正在被解除分类,因此拆分视图控制器委托不再是对有效对象的引用。

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.

您可以在prepareForSegue中更新委托:发件人:。例如:

You can update the delegate in 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;
        }
    }
}

您使用的视图控制器委托取决于您的视图控制器层次结构。在最简单的情况下,分配给splitVC详细信息的任何视图控制器可能都需要是委托。您可能希望将它们全部基于处理共享拆分视图控制器委托逻辑的公共超类。

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. You may want to base them all on a common super class that handles the shared split view controller delegate logic.

这篇关于iOS - 带故事板的UISplitViewController - 多个主视图和多个详细视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆