0

这就是问题所在:我需要从非 UI 线程创建警报。但是,当我使用块执行此操作时,会出现“BAD ACCESS”错误。这是代码:

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user
{       
        [currentUser updateWithFacebookUser:user errorBlock:^(void) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                            message:@"Facebook login was unsuccessfult. It's already in the system." delegate:self cancelButtonTitle:@"Cancel"
                                                  otherButtonTitles:@"OK", nil];
            [alert show];
        }];
}

在 updateWithFacebookUser:errorBlock 中:

- (void)updateWithFacebookUser:(id<FBGraphUser>)facebookUser errorBlock:(void (^)(void))errorBlock
{
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        errorBlock();
    }];    
}

令我惊讶的是,当我显示没有任何障碍的警报时,一切正常:

  - (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user
    {       
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                message:@"Facebook login was unsuccessfult. It's already in the system." delegate:self cancelButtonTitle:@"Cancel"
                                                      otherButtonTitles:@"OK", nil];
                [alert show];
            }];
    }

我还注意到显示了警报,然后才发生错误。可能是什么问题?

4

0 回答 0