无法关闭 RootViewController
在 Xcode 4 中,我创建了一个 SplitView 项目,因此我有一个 DetailViewController 和一个 RootViewController。
在RootViewController的viewDidLoad()中,我在左侧添加了一个取消按钮,如下所示
// add a cancel button on the left side
cancelButton = [[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:@selector(cancelAction:)] autorelease];
self.navigationItem.leftBarButtonItem = cancelButton;
当显示RootViewController并单击取消按钮时,我想关闭RootViewController。在我的 cancelButton 处理程序中,我尝试过调用
#if 0
[self dismissModalViewControllerAnimated:YES];
#else
[self.navigationController popViewControllerAnimated:YES];
#endif
,但它们都不适合我。我已经尝试谷歌搜索几个小时但仍然没有找到解决方案。
有人可以告诉我如何关闭 RootViewController 吗?
感谢您的帮助
In Xcode 4 I've created a SplitView project, so I have a DetailViewController and a RootViewController.
In RootViewController's viewDidLoad(), I have added a cancel button on the left side like this
// add a cancel button on the left side
cancelButton = [[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:@selector(cancelAction:)] autorelease];
self.navigationItem.leftBarButtonItem = cancelButton;
When the RootViewController is displayed and I click on the cancel button, I want to close the RootViewController. In my cancelButton handler I've tried calling
#if 0
[self dismissModalViewControllerAnimated:YES];
#else
[self.navigationController popViewControllerAnimated:YES];
#endif
but neither one of them work for me. I've tried googling for hours but have still not found a solution.
Can someone please tell me how to close the RootViewController?
thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您正在尝试关闭纵向方向的 RootViewController 弹出窗口,因为在横向方向上它没有意义。
您可以这样做:
1)取消按钮处理程序:
2)popoverController在detailViewController中是私有的,因此您必须将其公开(或向detailview添加方法,该方法将有权访问popoverController属性并从RootViewController中的cancelAction调用此方法):
2.1 )
从
2.2)
里面删除
I'm assuming you're trying to close popover of RootViewController in portrait orientation because in landscape it doesn't make sense.
You can do it like this:
1) cancel button handler:
2) popoverController is private in detailViewController so you must make it public (or add method to detailview that will have access to popoverController property and call this method from cancelAction in RootViewController):
2.1) delete
from
2.2) add
inside