无法关闭 RootViewController

发布于 2024-11-17 10:35:00 字数 843 浏览 1 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕嗳→ 2024-11-24 10:35:00

我假设您正在尝试关闭纵向方向的 RootViewController 弹出窗口,因为在横向方向上它没有意义。

您可以这样做:

1)取消按钮处理程序:

-(void)cancelAction {
    [self.detailViewController.popoverController dismissPopoverAnimated:YES];
}

2)popoverController在detailViewController中是私有的,因此您必须将其公开(或向detailview添加方法,该方法将有权访问popoverController属性并从RootViewController中的cancelAction调用此方法):

2.1 )

@property (nonatomic, retain) UIPopoverController *popoverController;

@interface DetailViewController ()
...
@end

2.2)

@property (nonatomic, retain) UIPopoverController *popoverController;

里面删除

@interface DetailViewController : UIViewController

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:

-(void)cancelAction {
    [self.detailViewController.popoverController dismissPopoverAnimated:YES];
}

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

@property (nonatomic, retain) UIPopoverController *popoverController;

from

@interface DetailViewController ()
...
@end

2.2) add

@property (nonatomic, retain) UIPopoverController *popoverController;

inside

@interface DetailViewController : UIViewController
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文