问题在于:我需要从非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];
}];
}
此外,我注意到警报已显示,然后才会发生错误。可能是什么问题?