我UIAlertView
在主线程上显示 a 时遇到问题。我不知道为什么,但它一直在崩溃,尽管我在主线程上运行。以下块在后台线程上,但我在主线程上有如下警报:
void (^removeFromCalendar)(NSString *, NSString *, EKEventStore *) = ^(NSString *error, NSString *eventKey, EKEventStore *eventDB) {
EKEvent *myEvent = [eventDB eventWithIdentifier:eventKey];
NSError *err = noErr;
if(myEvent != NULL && myEvent != (id)[NSNull null]) {
[eventDB removeEvent:myEvent span:EKSpanThisEvent error:&err];
} else {
// Event was not found, nothing to do
return;
}
[eventDB release];
if (!err || err == noErr) {
NSLog(@"Deleted event %@", myEvent.title);
// Show alert on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
// Showing the alert for unattending
NSString *resultString = @"This event was removed from your calendar.";
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Info" message:resultString delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil] autorelease];
[alert show];
});
return;
}
error = err.description;
};
如果我注释掉显示警报的底部,一切都很好。但是对于警报,我不断收到EXC_BAD_ACCESS
错误消息。有人可以解释为什么吗?它在正确的线程上,我一生都无法理解内存问题可能来自哪里!