ios - 方法未运行 - iOS

标签 ios objective-c cocoa-touch methods uialertview

我有一个非常简单的方法。但是在该方法中,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 之前和之后的代码都会在这个方法中运行……所以到底是哪里错了??

感谢您的宝贵时间。

最佳答案

您很可能不是在主线程上调用 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];
});

关于ios - 方法未运行 - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23344749/

相关文章:

objective-c - 关于使用@property @synthesize 释放对象的问题

ios - 在 UITableViewCell 中设置边框并在滚动时闪烁的问题

c++ - 从 C++ 和 Objective-C++ 链接 Cocoa Framework

c - 如何使用共享静态库避免 xcode 中的 "duplicate symbol"错误?

ios - 如果用户拒绝推送通知提示的回调方法?

ios - 贝塞尔路径的透明区域不允许用户交互

ios - 将数据传递到 Web 服务时出错。 'NSInvalidArgumentException' , 原因 : 'Invalid (non-string) key in JSON dictionary'

cocoa-touch - NSXMLParser 错误代码突然=5

iphone - 如何在 iOS 上查询电子邮件

iphone - ScrollView 为圆形