ios - 带有七个选项卡的选项卡栏 Controller ,五个选项卡导致 Split View Controller

标签 ios objective-c uiviewcontroller uitabbarcontroller uisplitviewcontroller

我已经做了很多研究并阅读了很多关于将 Tab Bar Controllers 与 Split View Controllers 一起使用的信息,但似乎找不到任何关于如何解决我的问题的提示...

Apple Developer Forum for Cocoa Touch 中标题为 "Place SplitViewController inside TabBarController" 的以下帖子到目前为止给了我最大的领先优势。

As of iOS 8, embedding a Split View Controller in a tab bar controller (or your own container view controller) is supported and expected to 'just work'. Pushing a split view controller onto a navigation stack remains unsupported.

这似乎违反了 Apple 文档,包括这篇标题为 "Combined View Controller Interfaces" 的文章日期为 2014 年 11 月。

You can use the view controllers that the UIKit framework provides by themselves or in conjunction with other view controllers to create even more sophisticated interfaces. When combining view controllers, however, the order of containment is important; only certain arrangements are valid. The order of containment, from child to parent, is as follows:

  • Content view controllers, and container view controllers that have flexible bounds (such as the page view controller)
  • Navigation view controller
  • Tab bar controller
  • Split view controller

我有一个 UITabBarController有七个选项卡。其中,五个选项卡指向 UISplitViewController s 和两个制表符导致 UINavigationController

这是一些 Storyboard 的屏幕截图,显示了标签栏 Controller 导致五个 Split View Controller 中的三个... Screenshot of <code>UIStoryboard</code>

当我使用 self.traitCollection.horizontalSizeClass = UIUserInterfaceSizeClassRegular 运行目标时没问题- 设备屏幕的水平(宽度)尺寸为常规(非紧凑型)-> 在 iPad 上运行。所有七个选项卡都出现在底部选项卡栏中,并且所有 View Controller (包括 Split View Controller )都可以完美运行。

我的问题?

当我使用 self.traitCollection.horizontalSizeClass = UIUserInterfaceSizeClassCompact 运行目标时,Xcode 报错并卡住应用程序操作- 设备屏幕的水平(宽度)尺寸为紧凑型 -> 在 iPhone 或 iPhone Plus 上运行。对于 IB 和 iOS 设备,结果与预期相同。

错误信息: Split View Controllers cannot be pushed to a Navigation Controller <UIMoreNavigationController: 0x7ffda38b0200>

我知道我收到错误的原因。在水平尺寸类别为“紧凑”的情况下,屏幕上的七个选项卡减少到五个,包括一个(iOS 专门准备的)“更多”选项卡。其余三个选项卡归属于“更多”选项卡,它是自己的导航 Controller 和 TableView Controller 。我的 Storyboard正试图将 Split View Controller 推送到此导航堆栈。

对合法的解决方案有什么想法吗?

最佳答案

我建议使用带有“更多”部分的自定义选项卡栏 Controller ,该部分不会将 View Controller 推送到导航 Controller 中。最好是 UITabBarController 的子类,这样您就可以将它与 Interface Builder 一起使用。

我的方法是用您自己的 View Controller 替换当前的“更多” TableView Controller ,该 View Controller 显示溢出选项卡列表,但在显示时不会将其相应的 View Controller 推送到导航栏中。

一种可能的策略是成为 UITabBarController 的更多导航 Controller (位于选项卡栏 Controller 的 moreNavigationController 属性中)的委托(delegate)。如果要显示的 View Controller 不是您自定义的“更多” View Controller ,则使用委托(delegate)方法(例如 navigationController:willShowViewController:animated:)替换导航 Controller 的 viewControllers 数组的内容。

我还没有尝试过这个,但这似乎是一个很好的起点,并且不需要太多的 tabview Controller 内部知识。

关于ios - 带有七个选项卡的选项卡栏 Controller ,五个选项卡导致 Split View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33871819/

相关文章:

ios - 如何让 shouldPerformSegueWithIdentifier 等到 block 完成

iphone - ALAssetsLibrary 获取视频路径稍后播放

ios - 如何使用 actionsheet showInView 方法,以便它可以在我的 VC 和 UIView 中显示

ios - 用户注销时返回到初始 View Controller

iphone - UI TableView 单元格在 swift 中使用 coredata 打开包含多个数据的新 View

ios - xcode 将不同的最大字符长度设置为不同的 TextField

iphone - 在iPhone应用程序中实现HMAC加密算法

ios - 不能在 Storyboard之间继续

ios - 使用哪种方法在启动时设置变量?

ios - 从 AppDelegate 通知 View Controller 的正确方法是什么?