【发布时间】:2016-11-02 20:44:38
【问题描述】:
我有一个符合 MFMessageComposeViewControllerDelegate 协议的 VC。
我成功地向这个视图控制器展示了以下代码:
- (IBAction)textAction:(id)sender {
if(![MFMessageComposeViewController canSendText])
{
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your device doesn't support SMS!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[warningAlert show];
return;
}
NSString *numberToCallOrText = self.phoneNumber;
NSString *message = @"Test message";
NSArray *recipients = [NSArray arrayWithObject:numberToCallOrText];
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setRecipients:recipients];
[messageController setBody:message];
// Present message view controller on screen
[self.view endEditing:YES];
[self presentViewController:messageController animated:YES completion:nil];
}
另外,我正在像这样处理完成结果:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult) result
{
switch (result) {
case MessageComposeResultCancelled:
NSLog(@"Canceled");
break;
case MessageComposeResultFailed:
{
NSLog(@"Failed");
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Failed to send SMS!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[warningAlert show];
break;
}
case MessageComposeResultSent:
NSLog(@"sent");
[self.navigationController popViewControllerAnimated:YES];
break;
default:
break;
}
[controller.view endEditing:YES];
[self.navigationController popViewControllerAnimated:YES];
// [self dismissViewControllerAnimated:YES completion:nil];
// [controller popToViewController:self animated:YES];
// [controller dismissViewControllerAnimated:YES completion:nil];
}
三个注释掉的行是我尝试过的替代方案。发生的事情是 MFMessageComposeViewController 保留在屏幕上(尽管键盘已关闭),但委托正在从堆栈中弹出。因此,当我再次点击取消时,我得到一个空引用错误。
这很奇怪,因为同样的实现在我的代码中的其他地方也可以使用。唯一的区别是我设置了要初始化的主体。
知道为什么这里会弹出错误的 VC 吗?
谢谢。
编辑 - 损坏的实现是在 UITableViewController 而不是 UIView 控制器上......这可能是导致问题的原因吗?
【问题讨论】:
-
除了对 TableVC 的编辑之外,一切都(在某一时刻)完全以相同的方式实现。甚至注释掉了
setBody电话。它仍然可以在应用程序的其他地方工作。只是这里取消按钮不起作用。
标签: ios objective-c uinavigationcontroller mfmessagecomposeview