dismissModalViewControllerAnimated from custom UITableView c



用户单击cell后,我在一些代码之后执行此操作:

[self.window.rootViewController presentModalViewController:mailer animated:YES];

然后当他点击取消按钮或发送此方法时:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[[((UIViewController *)(self.superview.superclass)) presentedViewController] dismissModalViewControllerAnimated:NO];
}

但是我的应用程序崩溃并熄灭了。

012-12-17 18:52:09.243 testapp[8293:15203] Mail cancelled: you cancelled the operation and no email message was queued
2012-12-17 18:52:09.243 testapp[8293:15203] +[UIResponder presentedViewController]: unrecognized selector sent to class 0xbb5db0
2012-12-17 18:52:09.244 testapp[8293:15203] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIResponder presentedViewController]: unrecognized selector sent to class 0xbb5db0'
*** First throw call stack:
(0x1ba6022 0x1688cd6 0x1ba7aad 0x1b0ced0 0x1b0ccb2 0x4e466 0xa99bf 0xac64f 0xa63f2 0x8d05af 0x1ba7e99 0x50f14e 0x50f0e6 0x5b5ade 0x5b5fa7 0x5b5266 0x5343c0 0x5345e6 0x51adc4 0x50e634 0x1d39ef5 0x1b7a195 0x1adeff2 0x1add8da 0x1adcd84 0x1adcc9b 0x1d387d8 0x1d3888a 0x50c626 0x370d 0x26c5 0x1)

尝试[controller dismissModalViewControllerAnimated:NO];

> 尝试简单[self dismissViewControllerAnimated:NO completion:nil]

如果您尝试从 VC 中关闭,那么这应该可以工作:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
   [self dismissModalViewControllerAnimated:NO];
}

崩溃的原因是 presentViewController 仅存在于 iOS 5 及更高版本上。如果您在iOS 4上运行它,则会导致您显示的异常。

dismissModalViewController 是关闭 iOS 4+5 版 presentModalViewController 的控制器的正确方法。它仍然适用于iOS 6,但已被弃用。在那里,您呈现视图控制器并关闭视图控制器。

最新更新