Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
方法未运行-iOS_Ios_Objective C_Cocoa Touch_Methods_Uialertview - Fatal编程技术网

方法未运行-iOS

方法未运行-iOS,ios,objective-c,cocoa-touch,methods,uialertview,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

我有一个非常简单的方法。但是,在方法中,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];
});

您很可能在主线程之外调用该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];
});


调试器里有什么吗?您是否在单独的线程中调用此“post_result”?如果你希望得到一个好的答案,我会发布更多的代码。你说它不会运行是什么意思?它不会显示吗?请确保在主线程上显示警报。你如何调用
post\u result
?是@rmaddy你是对的。我通过内置的twitterapi从twitterapi请求调用该程序。这一定使该方法在单独的线程中运行。谢谢。调试器里有什么吗?您是否在单独的线程中调用此“post_result”?如果你希望得到一个好的答案,我会发布更多的代码。你说它不会运行是什么意思?它不会显示吗?请确保在主线程上显示警报。你如何调用
post\u result
?是@rmaddy你是对的。我通过内置的twitterapi从twitterapi请求调用该程序。这一定使该方法在单独的线程中运行。谢谢。这不应该是
调度\u sync()
?谢谢,您也可以这样做[[NSOperationQueue mainQueue]addOperationWithBlock:我想。问题是我是通过内置的Twitter框架从Twitter API调用调用该方法的。我想这使它运行在一个单独的线程上。@特洛伊木马程序只需要是
dispatch\u sync
就可以了,当调度的代码在主队列上运行时,你希望后台线程被阻止。没有意义在这种情况下,@Supertecnoboff您可以使用NSOperationQueue,但在这种情况下确实不需要它。苹果建议您使用GCD来处理这种类型的事情。如果您想在单独的线程上启动/停止/恢复事情,则应主要使用NSOperations,这在您的情况下是不需要的。@Pete42啊,好的。非常感谢您在中提供的详细信息编队。确实非常有用。这不应该是
dispatch\u sync()
?谢谢,您也可以这样做[[NSOperationQueue mainQueue]addOperationWithBlock:我想。问题是我是通过内置的Twitter框架从Twitter API调用调用该方法的。我想这使它运行在一个单独的线程上。@特洛伊木马程序只需要是
dispatch\u sync
就可以了,当调度的代码在主队列上运行时,你希望后台线程被阻止。没有意义在这种情况下,@Supertecnoboff您可以使用NSOperationQueue,但在这种情况下确实不需要它。苹果建议您使用GCD来处理这种类型的事情。如果您想在单独的线程上启动/停止/恢复事情,则应主要使用NSOperations,这在您的情况下是不需要的。@Pete42啊,好的。非常感谢您在中提供的详细信息真的很有帮助。