我有一个UIAlertView
带 2 个按钮的。但我无法得到它的clickedButtonAtIndex
事件。问题是因为 - (void)dealloc
方法被过早地调用,我将代表设置为零。因此,无法处理警报视图按钮单击。这可能是什么原因。
编辑:我的代码有 2 个流向。在一个流动方向上,它工作正常。以正确的方式调用了 dealloc 方法。视图提前发布没有问题。
但是在第二个流程中,出现了这个问题。截至目前,我的理解是,[self retain]
在视图过早释放的情况下,我需要将 UIAlertView 委托设置为。但是我将如何检查视图是否被释放或仍然保留,以免打扰第一个流程?
我正在发布代码的相关部分。我认为这是视图被释放的地方。
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if(actionSheet.tag == 102)
{
if(buttonIndex == 0)
{
[self.infoView removeFromSuperview];
self.isSaveInfo = NO;
[self.doneButton.target performSelector:self.doneButton.action withObject:self.doneButton.target]; //This is where the view is getting released.
if([[NSBundle mainBundle] loadNibNamed:@"UploadView" owner:self options:nil])
{
[self.uploadView setFrame:CGRectMake(0, 0, 320, 480)];
[[UIApplication sharedApplication].keyWindow addSubview:self.uploadView];
}
[self performSelector:@selector(RemoveView) withObject:nil afterDelay:3.0];
}
if(buttonIndex == 1)
{
[self.infoView removeFromSuperview];
self.isSaveInfo = YES;
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadSaveButton) name:@"callThisMethod" object:nil];
MyInfoViewController *myInfoViewController = [[MyInfoViewController alloc]initWithNibName:@"MyInfoViewController" bundle:nil];
self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil] autorelease];
[self.navigationController myInfoViewController animated:YES];
[myInfoViewController release];
}
}
}
-(void)RemoveView
{
if([MyViewController OnSave])
{
self.testAlert = [[[ UIAlertView alloc]initWithTitle:messageTitle message:messageBody delegate:self cancelButtonTitle:messageClose otherButtonTitles:nil]autorelease];
self.testAlert.tag = 1;
[self.testAlert show];
[MyViewController setValue:NO];
}
else
{
self.testAlert = [[[ UIAlertView alloc]initWithTitle:messageTitle message:messageBody delegate:self cancelButtonTitle:messageClose otherButtonTitles:messageTryAgain, nil]autorelease];
self.testAlert.tag = 2;
[self.testAlert show];
}
}
-(void)loadSaveButton
{
[doneButton.target performSelector:doneButton.action];
if([[NSBundle mainBundle] loadNibNamed:@"UploadView" owner:self options:nil])
{
[self.uploadView setFrame:CGRectMake(0, 0, 320, 480)];
[[UIApplication sharedApplication].keyWindow addSubview:self.uploadView];
}
[self performSelector:@selector(RemoveView) withObject:nil afterDelay:3.0];
}
按钮 0 索引内的代码UIActionSheet
是视图被释放的地方,而按钮 1 索引工作正常。