简体   繁体   English

iOS 5-按钮停止工作

[英]iOS 5 - buttons stop working

I am developing an app and have accidentally been running it on iOS Simulator 4.3; 我正在开发一个应用程序,并且意外地在iOS Simulator 4.3上运行了该应用程序; the app works fine. 该应用程序运行正常。

Upon changing to iOS5 simulator, a button which is supposed to dismiss a modal view controller, no longer works? 更改为iOS5模拟器后,应该关闭模式视图控制器的按钮不再起作用了吗? Any ideas why? 有什么想法吗?

Below is my code: 下面是我的代码:

(Method to call controller): (调用控制器的方法):

if (self.infoModalController == nil)
    self.infoModalController = [[[InformationViewController alloc] initWithNibName:
                                   NSStringFromClass([InformationViewController class]) bundle:nil] autorelease];

[self.navigationController presentModalViewController:self.infoModalController animated:YES];

(Method to dismiss): (解雇方法):

- (void)dismissButtonPressed:(id)sender
{
[self.parentViewController dismissModalViewControllerAnimated:YES];
}

The view loads fine but it won't dismiss? 视图加载良好,但不会关闭吗?

Cheers in advance! 提前加油!

Lawrence 劳伦斯

For iOS 5 you want to use presentingViewController in place of parentViewController. 对于iOS 5,您想使用presentingViewController代替parentViewController。

Here are the relevant docs: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/parentViewController 以下是相关文档: http : //developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/parentViewController

Update: I should mention that calling [self dismissModalViewController] from the modal will have the same result, the dismiss selector is just passed up the responder chain to the presenter. 更新:我应该提到,从模态中调用[self dismissModalViewController]将具有相同的结果,dismiss选择器只是沿着响应者链向上传递给演示者。

When dismissing a modal view controller, it's safer to just do [self dismissModalViewControllerAnimated:YES] . 消除模式视图控制器时,只需执行[self dismissModalViewControllerAnimated:YES]安全。 This message can be sent to both the parent view or the modal view . 该消息可以发送到父视图或模式视图
The solution would be to this: 解决方案是:

- (void)dismissButtonPressed:(id)sender
{
    [self.parentViewController dismissModalViewControllerAnimated:YES];
}

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

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