单击按钮EXC_BAD_ACCESS之前发生警报崩溃

时间:2015-01-20 17:15:40

标签: ios objective-c uialertview exc-bad-access

我需要发出警告提醒,在单击“确定”之前执行操作,默认UIAlert在点击之前崩溃没有任何错误,所以我尝试使用SIAlert,但它也崩溃了,错误是EXC_BAD_ACCESS ......如何要解决这个问题?请帮帮我? Xcode 6.1.1

- (IBAction)share:(id)sender {

SIAlertView *alertView = [[SIAlertView alloc] initWithTitle:@"Post to VK wall?" andMessage:@"Do u want 2 post VK?"];


[alertView addButtonWithTitle:@"OK"
                         type:SIAlertViewButtonTypeCancel
                      handler:^(SIAlertView *alertView) {
                          NSLog(@"Button3 Clicked");
                      }];
[alertView addButtonWithTitle:@"CANCEL"
                         type:SIAlertViewButtonTypeDestructive
                      handler:^(SIAlertView *alertView) {
                          NSLog(@"Button2 Clicked");
                      }];

alertView.willShowHandler = ^(SIAlertView *alertView) {
    NSLog(@"%@, willShowHandler", alertView);
};
alertView.didShowHandler = ^(SIAlertView *alertView) {
    NSLog(@"%@, didShowHandler", alertView);
};
alertView.willDismissHandler = ^(SIAlertView *alertView) {
    NSLog(@"%@, willDismissHandler", alertView);
};
alertView.didDismissHandler = ^(SIAlertView *alertView) {
    NSLog(@"%@, didDismissHandler", alertView);
};

[alertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];

alertView.title = @"Postin VK";}

http://i.stack.imgur.com/kwn9Y.png - image og err

2 个答案:

答案 0 :(得分:0)

替换它:

[alertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];

用这个:

[alertView show];

我认为它没有找到@selector(show)

答案 1 :(得分:0)

alertView在方法结束时被释放,这就是你获得异常的原因。

你应该在课堂上强烈提及它。像这样:

@implementation MyClass {
    SIAlertView *_alertView;
}

- (IBAction)share:(id)sender {
    _alertView = [[SIAlertView alloc] initWithTitle:@"Post to VK wall?" andMessage:@"Do u want 2 post VK?"];
    ...
}

@end