xcode 在 iOS 5 Storyboard 中,如何将新场景从 Popover 推送到原始视图控制器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7786677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:08:55  来源:igfitidea点击:

In an iOS 5 Storyboard, how do you push a new scene to the original view controller from a Popover?

iosxcodeuipopovercontrollerios5storyboard

提问by lnafziger

I'm creating a popoverSegue from a new view controller and want to push a third view controller onto the original stack. This is how I'm creating the application:

我正在从一个新的视图控制器创建一个 popoverSegue,并希望将第三个视图控制器推送到原始堆栈上。这就是我创建应用程序的方式:

  1. Create a new Single View Application
  2. Select Use Storyboards
  3. Select the MainStoryboard.storyboardfile.
  4. Select the only View Controller, change the Titleand Identifierto initialView, then select Editor->Embed In->Navigation Controller
  5. Drag two new View Controllerobjects from the Objects Library onto the canvas
  6. Change the Titleand Identifierof the new View Controllers to: popoverViewand newView.
  7. Add a Round Rect Buttonobject from the Object Library to initialViewand popoverView.
  8. Add a Labelobject from the Object Library to `newView.
  9. Control click the button in the initialViewand drag to popoverView.
  10. Select the Popoveroption from the Storyboard Seguesmenu that appears.
  11. Control click the button in the popoverViewand drag to the newView.
  12. Select the Pushoption fromt the Storyboard Seguesmenu.
  13. Build & Run.
  1. 创建一个新的 Single View Application
  2. 选择 Use Storyboards
  3. 选择MainStoryboard.storyboard文件。
  4. 选择唯一的 View Controller,将Title和更改IdentifierinitialView,然后选择Editor->Embed In->Navigation Controller
  5. 将两个新View Controller对象从对象库拖到画布上
  6. 将新视图控制器的Title和更改Identifier为:popoverViewnewView
  7. Round Rect Button将对象库中的对象添加到initialViewpopoverView
  8. Label将对象库中的对象添加到`newView。
  9. 控制单击 中的按钮initialView并拖动到popoverView
  10. PopoverStoryboard Segues出现的菜单中选择选项。
  11. Control 单击 中的按钮popoverView并拖动到 中newView
  12. PushStoryboard Segues菜单中选择选项。
  13. 构建和运行。

Click the first button, and the popover appears, but when you click the button within the popover, nothing happens (it should push the new view but doesn't.)

单击第一个按钮,弹出框出现,但是当您单击弹出框内的按钮时,什么也没有发生(它应该推送新视图但没有。)

What I wantto do is for it to push onto the Navigation Controllerstack, but am not sure how to setup the storyboard for that.

想要做的是让它推送到Navigation Controller堆栈上,但我不确定如何为此设置故事板。

Any ideas?

有任何想法吗?

回答by Mark Adams

You're expecting the UINavigationControllerhierarchy to extend itself into a presented popover. It won't. The same goes for presenting modal view controllers. If you were to log self.navigationControllerin popoverView, you would see that it is nil.

您期望UINavigationController层次结构将自身扩展到呈现的弹出窗口中。不会。呈现模态视图控制器也是如此。如果你登录self.navigationControllerpopoverView,你会看到,它是零。

Embed popoverViewinto it's own UINavigationController. Remember that if you're overriding prepareForSegue:sender:and attempting to configure the popover, you will need to get the topViewControllerfrom destinationViewControlleras the destination is now an instance of UINavigationController.

嵌入popoverView到它自己的UINavigationController. 请记住,如果您要覆盖prepareForSegue:sender:并尝试配置弹出窗口,则需要获取topViewControllerfromdestinationViewController因为目标现在是UINavigationController.

回答by UntitledNo4

Sounds like it should work, but if it doesn't try the following: 1. Click the segue that doesn't work and give it an identifier. Let's say it's PopoverToNewSegue.

听起来它应该可以工作,但如果它没有尝试以下操作: 1. 单击不工作的 segue 并为其指定一个标识符。假设它是 PopoverToNewSegue。

  1. In your implementation file for the popover view controller, add an action when the button is clicked.

  2. That function should return void and add the following line: [self performSegueWithIdentifier:@"PopoverToNewSegue" sender:self];

  1. 在弹出视图控制器的实现文件中,在单击按钮时添加一个操作。

  2. 该函数应该返回 void 并添加以下行: [self performSegueWithIdentifier:@"PopoverToNewSegue" sender:self];

That should get your segue running. I've noticed that segues don't always work like you expect them to, but this one works for me without fail.

这应该让你的 segue 运行。我注意到 segues 并不总是像你期望的那样工作,但是这个对我来说没有失败。