您正在解除视图控制器,因此
delegate:self
导致撞车的原因是
[self dismissViewControllerAnimated:YES completion:nil];
self
不再可用。它被解除分配,向解除分配的对象发送消息导致崩溃。
尝试制作
delegate:nil
如果你不想使用
UIAlertView
委托方法。
或使用委托方法,确保
UIViewController <UIAlertViewDelegate>
那就做吧
if ([self.managedObjectContext save:&error]) {
[self fireAlert];
} else {
if (error) {
NSLog(@"Unable to save record.");
NSLog(@"%@, %@", error, error.localizedDescription);
}
}
-(void) fireAlert {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Thank you!" message:@"We appreciate your feedback" delegate:self
cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
// Dismiss View Controller
[self dismissViewControllerAnimated:YES completion:nil];
}