2014-04-28 2 views
0

매우 간단한 방법이 있습니다. 그러나 UIAlertView가 실행되지 않습니다 방법에 .... 여기 내 방법 :메서드 실행 안함 - iOS

-(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이 방법에서 실행 한 후 .... 그래서 접지 틀린거야 ??

감사합니다.

+2

디버거의 내용은 무엇입니까? 이 "post_result"를 별도의 스레드에서 호출 하시겠습니까? 좋은 대답을 얻으 려한다면 더 많은 코드를 게시 할 것입니다. –

+0

그것이 실행되지 않는다는 것을 의미합니까 - 표시되지 않습니까? – thegrinner

+4

주 스레드에 경고가 표시되는지 확인하십시오. – rmaddy

답변

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]; 
}); 
+0

그것은'dispatch_sync()'가 아니어야합니까? – trojanfoe

+0

감사합니다. 그리고 [[NSOperationQueue mainQueue] addOperationWithBlock : 나는 생각합니다. 문제는 내장 된 Twitter 프레임 워크를 통해 Twitter API 호출에서 메서드를 호출한다는 것이 었습니다. 나는 이것이 이것이 별도의 스레드에서 실행되고 있다고 생각한다. – Supertecnoboff

+0

@trojanfoe 디스패치 된 코드가 주 큐에서 실행되는 동안 백그라운드 스레드를 차단하려면 'dispatch_sync' 만 필요합니다. 이 경우에는 아무런 의미가 없습니다. – rmaddy