-2

用户点击后,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)
4

4 回答 4

0

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

于 2012-12-17T16:43:07.113 回答
0

如果您试图从 VC 中解散,那么这应该有效:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
   [self dismissModalViewControllerAnimated:NO];
}
于 2012-12-17T16:43:46.187 回答
0

尝试 [controller dismissModalViewControllerAnimated:NO];

于 2012-12-17T17:11:21.337 回答
0

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

对于 iOS 4+5,dismissModalViewController 是关闭使用 presentModalViewController 呈现的控制器的正确方法。它仍然适用于 iOS 6,但已被弃用。在那里你展示了ViewController 和dismissViewController。

于 2012-12-17T17:34:08.313 回答