在 iOS 5 Storyboard 中,如何将新场景从 Popover 推送到原始视图控制器?
我正在从新的视图控制器创建 popoverSegue,并希望将第三个视图控制器推送到原始堆栈上。这就是我创建应用程序的方式:
- 创建一个新的
单视图应用程序
- 选择
使用 Storyboards
- 选择
MainStoryboard.storyboard
文件。 - 选择唯一的View Controller,将
Title
和Identifier
更改为initialView
,然后选择Editor->Embed In->Navigation控制器
- 将两个新的
View Controller
对象从对象库拖到画布上, - 将新视图控制器的
Title
和Identifier
更改为:popoverView
和newView
。 - 将对象库中的
Round Rect Button
对象添加到initialView
和popoverView
。 - 将对象库中的
Label
对象添加到 `newView. - Control 单击
initialView
中的按钮并拖动到popoverView
。 - 从出现的
Storyboard Segues
菜单中选择Popover
选项。 - Control 单击
popoverView
中的按钮并拖动到newView
。 - 从
Storyboard Segues
菜单中选择Push
选项。 - 构建&跑步。
单击第一个按钮,弹出窗口出现,但是当您单击弹出窗口中的按钮时,没有任何反应(它应该推送新视图,但没有。)
我想要做的是它推入导航控制器堆栈,但我不确定如何为此设置故事板。
有什么想法吗?
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:
- Create a new
Single View Application
- Select
Use Storyboards
- Select the
MainStoryboard.storyboard
file. - Select the only View Controller, change the
Title
andIdentifier
toinitialView
, then selectEditor->Embed In->Navigation Controller
- Drag two new
View Controller
objects from the Objects Library onto the canvas - Change the
Title
andIdentifier
of the new View Controllers to:popoverView
andnewView
. - Add a
Round Rect Button
object from the Object Library toinitialView
andpopoverView
. - Add a
Label
object from the Object Library to `newView. - Control click the button in the
initialView
and drag topopoverView
. - Select the
Popover
option from theStoryboard Segues
menu that appears. - Control click the button in the
popoverView
and drag to thenewView
. - Select the
Push
option fromt theStoryboard Segues
menu. - Build & Run.
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 want to do is for it to push onto the Navigation Controller
stack, but am not sure how to setup the storyboard for that.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您期望 UINavigationController 层次结构将自身扩展为呈现的弹出窗口。不会的。呈现模态视图控制器也是如此。如果您要在
popoverView
中记录self.navigationController
,您会看到它为 nil。将
popoverView
嵌入到它自己的UINavigationController
中。请记住,如果您要覆盖prepareForSegue:sender:
并尝试配置弹出窗口,则需要从destinationViewController
获取topViewController
作为目的地现在是 UINavigationController 的一个实例。You're expecting the
UINavigationController
hierarchy to extend itself into a presented popover. It won't. The same goes for presenting modal view controllers. If you were to logself.navigationController
inpopoverView
, you would see that it is nil.Embed
popoverView
into it's ownUINavigationController
. Remember that if you're overridingprepareForSegue:sender:
and attempting to configure the popover, you will need to get thetopViewController
fromdestinationViewController
as the destination is now an instance ofUINavigationController
.听起来应该可行,但如果不起作用,请尝试以下操作:
1. 单击不起作用的 segue 并为其指定一个标识符。假设它是 PopoverToNewSegue。
在弹出视图控制器的实现文件中,在单击按钮时添加一个操作。
该函数应返回 void 并添加以下行:
[self PerformSegueWithIdentifier:@"PopoverToNewSegue" sender:self];
这应该能让你的segue运行起来。我注意到转场并不总是像你期望的那样工作,但是这个对我来说毫无失败。
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.
In your implementation file for the popover view controller, add an action when the button is clicked.
That function should return void and add the following line:
[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.