I have a very simply method. However in the method the UIAlertView will not run.... Here is my method:

-(void)post_result {
    NSLog(@"Post Result");

    post_now.enabled = YES;
    [active stopAnimating];
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Success" message:@"You're post has been successfully uploaded." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [alertView show];

    success_post_facebook = 0;
    success_post_youtube = 0;
    success_post_googleplus = 0;
    success_post_tumblr = 0;
    success_post_twitter = 0;

    NSLog(@"Post Result END");
}

The odd thing is that the code before and after the UIAlertView will run in this method.... So what an earth is wrong??

Thanks for your time.

有帮助吗?

解决方案

Your are most likely calling that UIAlertView not on the main thread. To make it run on the main thread just use the main dispatch queue like so.

dispatch_async(dispatch_get_main_queue(), ^{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Success" message:@"You're post has been successfully uploaded." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [alertView show];
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top