我正在努力查看视图层次结构,但我无法弄清楚这里出了什么问题。我尝试发送消息(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];
}
如果有人能帮助我......
答案 0 :(得分:0)
您没有以适当的方式初始化<?php
include("includes/connect.php");
if(isset($_GET['id'])){
$get_id = $_GET['id'];
$get_query = "select * from posts where post_id='$get_id'";
$run_query = mysql_query($get_query);
while ($row=mysql_fetch_array($run_query)){
$post_id = $row['post_id'];
$post_title = $row['post_title'];
$post_image = $row['post_image'];
}
}
?>`
<div>
<h2> <?php echo $post_title;?> </h2>
</div>
。您正在使用相同的变量名alertController,它是公共的
UIAlertController
但不公开该方法。并且您正在使用对方法if (tag == 3) {
}
公开的相同变量名称
UIAlertController *alertController;
正在访问公共方法变量,即[self presentViewController:alertController animated:YES completion:nil];
,您已为标记1正确初始化。我建议您使用以下代码 -
UIAlertController *alertController;
希望它有所帮助。