IOS8 SplitVC TabBarController NavigationController

IOS8 SplitVC TabBarController NavigationController,第1张

概述我正在使用大小类进行通用应用程序,我正在尝试在主/主视图中使用带有TabBarController的SplitView.在添加splitView之前一切正常,但现在App崩溃了(原因取决于视图的层次结构). 所以我从Apple SplitView模板开始尝试相同的故事板,并在其主/主视图上添加一个TabBarController ……同样的问题. 层次结构 – TabBarController中的 我正在使用大小类进行通用应用程序,我正在尝试在主/主视图中使用带有TabbarController的SplitVIEw.在添加splitVIEw之前一切正常,但现在App崩溃了(原因取决于视图的层次结构).

所以我从Apple SplitVIEw模板开始尝试相同的故事板,并在其主/主视图上添加一个TabbarController ……同样的问题.

层次结构 – TabbarController中的嵌入式主NavigationController:
SplitVC(Master)> TabbarController> NavigationController>的tableVIEw
SplitVC(详情)> NavigationController>视图

在AppDelegate.m中添加了此代码(如此处所示,以防止DetailVIEw以模态方式呈现):

- (BOol)splitVIEwController:(UISplitVIEwController *)splitVIEwController showDetailVIEwController:(UIVIEwController *)vc sender:(ID)sender {        NSLog(@"UISplitVIEwController collapsed: %d",splitVIEwController.collapsed);    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)    {        if (splitVIEwController.collapsed) {            UITabbarController *master = (UITabbarController *) splitVIEwController.vIEwControllers[0];            UINavigationController *masterNavigationController = (UINavigationController *)master.selectedVIEwController;            UINavigationController *destinationNavigationController = (UINavigationController *)vc;            // push detail vIEw on the navigation controller            [masterNavigationController pushVIEwController:[destinationNavigationController.vIEwControllers lastObject] animated:YES];            return YES;        }    }    return NO;}

它工作正常…除非你在iPhone6 Plus中进行模拟,在这种情况下,在以纵向开始并选择一行后,如果你在横向旋转我会看到详细视图作为主要和次要视图.

如果不使用iPhone以纵向方式添加此代码,则会以模态方式呈现详细视图,当然也不会显示导航按钮.

编辑

经过不同的尝试和一些外部帮助,我已经向前迈出了一些步骤.

简短版本(请参阅长版本以了解您必须执行此 *** 作的原因)

该问题的正确解决方案是继承TabbarController并使其支持一些方法:

@implementation MyTabbarController- (voID)showVIEwController:(UIVIEwController *)vc sender:(ID)sender{    if ([self.selectedVIEwController isKindOfClass:UINavigationController.class])        [self.selectedVIEwController showVIEwController:vc sender:sender];    else        [super showVIEwController:vc sender:sender];}- (UIVIEwController*)separateSecondaryVIEwControllerForSplitVIEwController:(UISplitVIEwController *)splitVIEwController{    return [self.selectedVIEwController separateSecondaryVIEwControllerForSplitVIEwController:splitVIEwController];}- (voID)collapseSecondaryVIEwController:(UIVIEwController *)secondaryVIEwController forSplitVIEwController:(UISplitVIEwController *)splitVIEwController{    [self.selectedVIEwController collapseSecondaryVIEwController:secondaryVIEwController forSplitVIEwController:splitVIEwController];}

现在我遇到了vIEwControllers堆栈的问题:使用iPhone6Plus(唯一一个支持水平常规和紧凑)的应用程序崩溃,如果在横向时,您更改选项卡而不选择行(因此detailVIEw仍然是前一个选项卡的那个) )然后纵向旋转.

我知道我必须实现正确管理视图堆栈的分离和折叠方法,但我无法弄清楚如何.有人可以帮忙吗?

Long version (SplitVIEwController behavIoUr)

normally a split vIEw controller and a navigation controller work
together to ensure that a call to -showDetailVIEwController:sender:
from a vIEw controller that is contained within the split vIEw
controller results in the new detail vIEw controller being pushed onto
the navigation stack (when in a horizontally compact environment). To
do this,UISplitVIEwController overrIDes
-showDetailVIEwController:sender: and,if horizontally compact,calls its master vIEw controller’s -showVIEwController:sender: method.
UINavigationController overrIDes -showVIEwController:sender: and
pushes the incoming vIEw controller onto the navigation stack.

UITabbarController however does not overrIDe
-showVIEwController:sender: and so it inherits the default implementation which presents the incoming vIEw controller modally.
To work around this I have to subclass UITabbarController and overrIDe
-showVIEwController:sender: to forward to the tab bar controller’s selectedVIEwController if the selectedVIEwController is a navigation
controller.

Furthermore,when a split vIEw controller Transitions from a compact
to horizontal size class to a regular horizontal size class,the split
vIEw controller first sends a
-splitVIEwController:separateSecondaryVIEwControllerFromPrimaryVIEwController:
message to its delegate. The delegate can implement this method and
handle the separation itself,returning the detail vIEw controller.
If the delegate does not implement this method,or if the
implementation returns nil,the split vIEw controller sends a
-separateSecondaryVIEwControllerForSplitVIEwController: message to its primary vIEw controller. The primary vIEw controller should implement
this method to handle the separation. The UINavigationController does
implement -separateSecondaryVIEwControllerForSplitVIEwController:.
It’s implementation pops the top vIEw controller off the navigation
stack and returns it. Because I am using a tab bar controller as the
primary vIEw controller,I must implement
-separateSecondaryVIEwControllerForSplitVIEwController: and handle the separation by myself.

Also I need to implement my own collapsing logic. When a split vIEw
controller Transitions from a regular to horizontal size class to a
compact horizontal size class,the split vIEw controller first sends a
-splitVIEwController:collapseSecondaryVIEwController:ontoprimaryVIEwController:
message to its delegate. The delegate can implement this method and
handle the collapse itself. If the delegate does not implement this
method,the split vIEw controller sends a
-collapseSecondaryVIEwController:forSplitVIEwController: message to its primary vIEw controller. The primary vIEw controller should
implement this method to handle the separation.

UINavigationController does implement
-collapseSecondaryVIEwController:forSplitVIEwController:. It’s implementation pushes the secondary vIEw controller onto the
navigation stack. Because I am using a tab bar controller as the
primary vIEw controller,I must implement
-collapseSecondaryVIEwController:forSplitVIEwController: and handle the collapse by myself.

解决方法 所以,我找到了一些有效的东西,即使它不是标准行为:

- (voID)collapseSecondaryVIEwController:(UIVIEwController *)secondaryVIEwController forSplitVIEwController:(UISplitVIEwController *)splitVIEwController{    [self.selectedVIEwController.navigationController collapseSecondaryVIEwController:secondaryVIEwController forSplitVIEwController:splitVIEwController];}

这相当于在splitVIEwController中返回始终为YES:collapseSecondaryVIEwController:ontoprimaryVIEwController:delegate方法.像这样你总是丢弃辅助控制器.希望这可以帮助别人.

总结

以上是内存溢出为你收集整理的IOS8 SplitVC TabBarController NavigationController全部内容,希望文章能够帮你解决IOS8 SplitVC TabBarController NavigationController所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1027222.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-23
下一篇2022-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存