문제

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