【发布时间】:2017-01-31 08:57:56
【问题描述】:
我在视图层次结构中苦苦挣扎,但我无法弄清楚这里出了什么问题。我尝试发送消息 (MFMessageComposeViewController)。我想在委托方法的帮助下根据成功(或不成功)显示alertView。取消消息时会显示 alertView 但发送消息时出现此错误:
Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UIAlertController: 0x153b3c00>)
看起来好像在发送消息时(好像还有一些东西在幕后运行),在 MFMessageComposeView 被完全解除(或解除分配)之前调用了完成块,但在它被取消时却没有。
如果有帮助:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
int tag;
switch (result) {
case MessageComposeResultCancelled:
{
tag = 1;
NSLog(@"Cancelled");
break;
}
case MessageComposeResultFailed:
{
tag = 2;
NSLog(@"Failed");
break;
}
case MessageComposeResultSent:
{
tag = 3;
NSLog(@"Sent");
break;
}
default:
break;
}
[controller dismissViewControllerAnimated:YES completion:^{
[self alertSMSMessageWithTag:tag];
}];
}
- (void)alertSMSMessageWithTag:(int)tag {
UIAlertController *alertController;
if (tag == 1) { // cancelled
alertController = [UIAlertController alertControllerWithTitle:@"Message cancelled" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:ok];
}
if (tag == 2) { // Failed
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Message failed" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:ok];
}
if (tag == 3) { // sent
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Message sent" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:ok];
}
[self presentViewController:alertController animated:YES completion:nil];
}
如果有人可以帮助我...
【问题讨论】:
标签: objective-c delegates uialertview mfmessagecomposeview