我通过以下方式将委托设置为 UIAlertView:
PhotoViewController *controller = [[PhotoViewController alloc] init];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Announcement"
message: @"It turns out that you are playing Addicus!"
delegate: controller
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
其中 PhotoViewController 不是当前的 UIviewContorller。警报加载正常,但只要我按下确定按钮,应用程序就会崩溃并且我收到此错误:
0x3a61a5b0: ldr r3, [r4, #8] EXC 错误访问
这是什么意思?
编辑:
+ (DejalActivityView *)activityViewForView:(UIView *)addToView withLabel:(NSString *)labelText width:(NSUInteger)aLabelWidth;
{
// Immediately remove any existing activity view:
if (dejalActivityView)
[self removeView];
// Remember the new view (so this is a singleton):
dejalActivityView = [[self alloc] initForView:addToView withLabel:labelText width:aLabelWidth];
if ([labelText isEqualToString:@"Uploading photo (this process might take a while)"]) {
buttonCancel = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[buttonCancel addTarget:dejalActivityView
action:@selector(callCancelAlert:)
forControlEvents:UIControlEventTouchDown];
buttonCancel.frame = CGRectMake(230, 540, 265, 40);
[addToView addSubview:buttonCancel];
[buttonCancel setImage:[UIImage imageNamed:@"socialize-navbar-bg.png"] forState:UIControlStateNormal];
[buttonCancel setTitle:@"Cancel upload" forState:UIControlStateNormal];
}
return dejalActivityView;
}
-(IBAction)callCancelAlert:(id)sender{
PhotoViewController *controller = [[PhotoViewController alloc] init];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Announcement"
message: @"It turns out that you are playing Addicus!"
delegate: controller
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
//[alert release];
}