简体   繁体   English

使用Xcode故事板创建主-主视图,其中“主视图”视图是“标签栏”到三个不同的视图

[英]Using Xcode Storyboard to create Master-Detail views where the Detail view is Tab Bar to three different views

I'm trying to implementing master-detail scenes where the detail scene can be tabbed to show three different scenes. 我正在尝试实现主从场景,在该场景中可以将详细信息场景显示为三个不同的场景。 The example is a list of stories and for each story, I am interested to present an introduction, author info and reviews. 这个例子是一个故事列表,对于每个故事,我有兴趣介绍一下简介,作者信息和评论。 So the scenes are as the following: 因此,场景如下:

  1. Master scene: a list of stories 主场景:故事列表

When a story is selected: 选择故事后:

  1. Detail - Introduction scene (about the selected story) 详细信息-简介场景(关于所选故事)
  2. Detail - Author scene (about the author) 详细信息-作者场景(关于作者)
  3. Detail - Reviews scene (a list of reviews) 详细信息-评论场景(评论列表)

I attached the storyboard that I used to kind of achieve this: https://docs.google.com/file/d/0B6I7Mlt7gqCBVTFZR2lsX0Q4MUk/edit?usp=sharing 我附上了以前用来实现此目的的故事板: https : //docs.google.com/file/d/0B6I7Mlt7gqCBVTFZR2lsX0Q4MUk/edit?usp=sharing

I also attached the resultant scene on the iPhone simulator that showed the Detail - Author scene: https://docs.google.com/file/d/0B6I7Mlt7gqCBQWhLTlNwWjZ2TG8/edit?pli=1 我还将结果场景附加到显示了“详细信息-作者”场景的iPhone模拟器上: https : //docs.google.com/file/d/0B6I7Mlt7gqCBQWhLTlNwWjZ2TG8/edit?pli=1

My problem is with there are 2 navigation bars presented in the detail - author scene: The top one with Stories back button, and the bottom one with Author label and B button. 我的问题是,详细信息中显示了2个导航栏-作者场景:最上面的一个带有“故事”后退按钮,最下面的一个带有“作者”标签和B按钮。 I want them to be collapsed into just one navigation bar. 我希望将它们折叠到一个导航栏中。 This means that when I click on a story from the Stories scene to transition to the detail author view, there will be only one navigation bar that has the Stories back button, the Author label, and the B button. 这意味着当我从“故事”场景中单击一个故事以切换到详细作者视图时,将只有一个导航栏带有“故事”后退按钮,“作者”标签和“ B”按钮。

My question is: How can I collapse these two navigation bars together? 我的问题是:如何将这两个导航栏折叠在一起? Any advice would be greatly appreciated. 任何建议将不胜感激。

The problem is that you have a root navigation controller and you also have a navigation controller in each tab of the tab controller, then you show them both at the same time. 问题是您有一个根导航控制器,并且在选项卡控制器的每个选项卡中也都有一个导航控制器,然后同时显示它们。

You could try a couple of things: 您可以尝试以下几种方法:

  1. Hide the root nav controllers nav bar when the tab view is on display. 显示选项卡视图时,隐藏根导航控制器导航栏。 This could be manual or by presenting modally. 这可以是手动的,也可以通过模态呈现。 In either case you will need a done / back button to dismiss. 无论哪种情况,您都需要一个完成/后退按钮来关闭。 The modal option could be done in the storyboard. 模态选项可以在情节提要中完成。

  2. Add a delegate to the tab bar controller. 将一个委托添加到选项卡栏控制器。 Remove the nav controllers from each tab. 从每个选项卡中删除导航控制器。 When the tab changes, get the new view controller and set its navigationItem onto the root nav controllers nav bar. 当选项卡更改时,获取新的视图控制器并将其navigationItem设置在根导航控制器的导航栏上。


Back button items are only shown when there is something to go back to. 后退按钮项仅在有需要返回的内容时显示。 You can add left button items. 您可以添加左键项目。 You may be able to connect them to an unwind segue or you might need to add a method to each view controller which does: 您可能可以将它们连接到展开序列,或者可能需要向每个视图控制器添加一个方法,该方法可以:

[self.tabBarController.navigationController popViewControllerAnimated:YES];

I figured out one solution: 我想出了一个解决方案:

Objectives: When combining a Master-Detail scheme with the Detail part spreads to several scenes via tab bar controller using Push segue from Master to the tab bar scene, I want to: 1). 目标:当将“主从细节”方案与“明细”部分结合使用,通过选项卡栏控制器使用从“主”到“选项卡栏”场景的Push segue扩展到多个场景时,我要:1)。 retain the back button from the push segue, 2). 保留按一下按钮上的后退按钮,2)。 set the navigation item on the tab bar scene to whichever detail scene that is visible, 3). 将标签栏场景上的导航项目设置为可见的任何细节场景,3)。 set the right button on the detail scene. 在细节场景上设置右键。 Another objective is to just use Storyboard to convey the GUI design and interaction flow, without getting into the code. 另一个目标是仅使用Storyboard来传达GUI设计和交互流程,而无需进入代码。

Problems: There were many problems with which controllers to use. 问题:使用哪个控制器存在很多问题。 (And one can play with the Xocde project that I uploaded here to see them.) One good solution is to use a navigation controller for each detail scene, which enables the bar button item to be added to the navigation bar on the detail scene (do not add a navigation bar to the detail scene yourself). (一个人可以玩我在这里上传的Xocde项目,以查看它们。)一个好的解决方案是对每个细节场景使用导航控制器,这使得可以将bar按钮项添加到细节场景的导航栏中(不要自己在细节场景中添加导航栏。 Just from Storyboard, this worked fine, except that the navigation bar from the navigation scene would show up under the navigation bar from the tab bar scene, and the upper navigation bar wouldn't have the correct title or the correct button on it. 只是从Storyboard上,它工作正常,除了导航场景中的导航栏将显示在选项卡场景中的导航栏下方,并且上方导航栏上没有正确的标题或正确的按钮。

Solutions: The basic use of all the scenes as described in the original post is fine. 解决方案:原始帖子中描述的所有场景的基本用法都可以。 For the programmatic changes part, create a view controller .h and .m for the detail scene. 对于程序性更改部分,为细节场景创建一个视图控制器.h和.m。 Then in the viewDidAppear method, retrieve the bar button that was added to the right side of the detail scene's navigation bar, and then assign it to the right bar button item on the tab bar scene's navigation bar. 然后,在viewDidAppear方法中,检索添加到详细场景导航栏右侧的按钮,然后将其分配给选项卡场景导航栏上的右按钮项。

The code snippet is as the follows - this is applicable to scenes that I described earlier: 该代码段如下所示-适用于我先前描述的场景:

    UIBarButtonItem *detailButton = self.navigationItem.rightBarButtonItem;
    self.parentViewController.parentViewController.navigationItem.rightBarButtonItem = detailButton;

On the Storyboard canvas, select the navigation scene, and make sure it's navigation bar is turned off. 在“情节提要”画布上,选择导航场景,并确保其导航栏已关闭。

One thing that I particularly liked abut this that the separation of the GUI design and flow are totally there. 我特别喜欢的一件事是,GUI设计和流程完全分开。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM