在UISplitViewController的详细视图中缺少标题栏 [英] Missing Title Bar in Detail View of UISplitViewController

查看:215
本文介绍了在UISplitViewController的详细视图中缺少标题栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在容器视图中嵌入了 UISplitViewController (因为它不在我的应用程序的根目录下),除了一个问题外,其机制运行良好: iPad上缺少详细视图的导航栏。

I have a UISplitViewController embedded in a container view (because it's not at the root of my app), the mechanics of which are working nicely except for one issue: The navigation bar for the detail view is missing on the iPad.

初始设置基本上如下:


  1. 在IB中,将拆分视图控制器拖到故事板上,从而创建拆分视图控制器,导航控制器,表视图控制器(主控),基本视图控制器(详细信息) )和连接它们的segues。

  2. 添加带有容器视图的常规View Controller。从容器视图到拆分视图控制器创建一个嵌入式搜索。

  3. 从原型单元添加另一个segue到Detail View Controller,由主控制器中的以下代码支持:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    self.performSegue(withIdentifier: "showDetail", sender: nil)
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "showDetail" {
        let destinationViewController = segue.destination as! DetailViewController
        let path = self.tableView.indexPathForSelectedRow! as  NSIndexPath
        destinationViewController.selectedTrainingId = (self.itemList[path.row] as! MyListItem).id
    }
}




  1. 添加数据。

将项目加载到主视图中并选择详细信息正在运行。

Loading the items into master view and selecting the detail are working.

以下是IB中的内容(为了节省空间,我展示了iPhone布局,但无论如何都应该可以看到关系):

Here is what it looks like in IB (to save space I show the iPhone layout but the relationships should be visible anyhow):

SO处理类似问题的答案很少。最接近的匹配建议为详细视图添加自己的导航控制器。我不明白为什么这是必要的,因为它在iPhone上按预期工作的事实我相信这表明详细视图使用与主(根)视图相同的导航控制器。但我试了一下。结果是,我怀疑,最初会显示一个导航栏。但是一旦选择了一个项目,该栏就会消失。以下是设置。

There are few answers in SO dealing with similar problems. Closest matches suggest adding an own navigation controller for the detail view. I did not understand why that would be necessary because the fact that it works as intended on the iPhone I believe shows that the detail view uses the same navigation controller as the master (root) view. But I gave it a try. Result is, as I suspected, that initially a navigation bar is shown. but as soon as an item is selected the bar disappears. Below is the setup.

在许多应用中(消息,电子邮件,Skype,...)您可以看到主视图和详细视图的单独顶部栏。虽然从技术上讲我的应用程序并不是绝对需要两者,但它并不是特别漂亮,尤其是彩色条。所以,问题是:如何获取详细信息视图的导航栏

In many apps (Messaging, Email, Skype, ...) you can see separate top bars for master and detail views. While technically my app does not absolutely need both, it is not really pretty especially with a colored bar. So, the question is: How can I get the Navigation Bar for the Detail View.

推荐答案

详细视图需要自己的导航控制器才能在iPad上显示导航栏。因此,问题中的第二个图像显示正确的设置,但细节segue需要指向导航控制器。

The detail view needs its own navigation controller to show a navigation bar on the iPad. So, the second image in the question shows the correct setup with the exception that the detail segue needs to point to the navigation controller.

关键是获取详细视图的句柄以设置所选的项目ID,这可以通过对原始代码进行少量更改来完成:

Key is to get a handle on the detail view in order to set the selected item id, which can be done with a small change to the original code:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "showDetail" {

        // Destination View Controller
        let destinationNavigationcontroller: UINavigationController! = segue.destination as! UINavigationController
        let destinationViewController: DetailViewController! = destinationNavigationcontroller.topViewController as! DetailViewController

        // Selected Row ID
        let path = self.tableView.indexPathForSelectedRow! as  NSIndexPath
        destinationViewController.selectedId = (self.itemList[path.row] as! MyListItem).id
    }
}

这篇关于在UISplitViewController的详细视图中缺少标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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