سؤال

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