ios - UITabBarController 中的 UISplitViewController 在尝试检查 [splitViewController viewControllers] 时出错

标签 ios objective-c ipad uitabbarcontroller uisplitviewcontroller

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    UISplitViewController *splitViewController = (UISplitViewController *)[[tabBarController viewControllers] firstObject];
    UINavigationController *navigationController = [[splitViewController viewControllers] lastObject];
    splitViewController.delegate = (id)navigationController.topViewController;
}

这是我当前用于检查设备是否为 iPad 的代码。如果是,它应该设置 tabbarcontroller 的第一个对象的最后一个对象的唯一 View Controller 。 Storyboard如下:

Tabbarcontroller[0]>Splitviewcontroller[1]>Navigationcontroller[0]>delegate(?)

我仍然不知道委托(delegate)的作用,但在检查苹果的 Split View Controller 模板代码后,我认为它使用委托(delegate)来通知详细 View Controller 更新内容。我崩溃的行是 [splitViewController viewControllers]

最佳答案

根据 Apple 指南 UISplitViewController 应该是 Root View Controller i。 e.它不能作为子 Controller 插入到 UITabBarController 中:

A split view controller must always be the root of any interface you create. In other words, you must always install the view from a UISplitViewController object as the root view of your application’s window.

来自“View Controller Catalog for iOS”用户指南

关于ios - UITabBarController 中的 UISplitViewController 在尝试检查 [splitViewController viewControllers] 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21138419/

相关文章:

ios - 在 UITableViewCell 中定位元素

iphone - 更改 UITabBarController 的 View Controller

ios - 在 swift 中捕获图像后,ipad 中图像的方向发生变化

objective-c - 使用带有pop over的drawRect,需要显示图像

ios - 实例和初始化的区别

ios - 将发布变量发送到我的 Api

objective-c - 如何将此 Swift 行转换为 Objective-C 语法

ios - 一个项目中多个 UIImage+ImageEffects 文件

iphone - iOS - 从 plist 数据滚动图像

ios - 如何修复 CloudKit Dashboard 中的 ZONE_NOT_FOUND 错误?