我有一个非常简单的方法。但是在方法中,UIAlertView将无法运行....这是我的方法:
-(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");
}
奇怪的是,UIAlertView之前和之后的代码将在这个方法中运行....那么地球是错的?
感谢您的时间。
答案 0 :(得分:4)
你很可能在主线程上调用UIAlertView。要使它在主线程上运行,只需使用主调度队列,如此。
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];
});