Iphone UIAlertView退出EXC\u错误\u访问错误
我有这样的错误:当我单击navigationbar.backItemButton时,我用两个按钮显示UIAlertView。当我按下其中任何一个按钮时,应用程序只会在EXC\u BAD\u访问时终止。方法-(void)alertView:(UIAlertView*)alertView单击按钮索引:(NSInteger)按钮索引不调用。我怎样才能解决它?塔克斯 //h文件Iphone UIAlertView退出EXC\u错误\u访问错误,iphone,uialertview,exc-bad-access,Iphone,Uialertview,Exc Bad Access,我有这样的错误:当我单击navigationbar.backItemButton时,我用两个按钮显示UIAlertView。当我按下其中任何一个按钮时,应用程序只会在EXC\u BAD\u访问时终止。方法-(void)alertView:(UIAlertView*)alertView单击按钮索引:(NSInteger)按钮索引不调用。我怎样才能解决它?塔克斯 //h文件 @interface DetailsTableViewController : UITableViewController &
@interface DetailsTableViewController : UITableViewController <UITextFieldDelegate, UIAlertViewDelegate>
视图控制器是否实现UIAlertViewDelegate?如果没有,请在{开始之前添加接口声明 还可以尝试在ClickedButtonIndex方法中登录,并打印buttonIndex值,然后查看控制台
编辑:再次阅读您的帖子,我想您确实错过了界面声明中的UIAlertViewDelegate; 你用错了吗 [信息发布] 因为您已经使用了[[UIAlertView alloc]init…];因此应该释放内存 autorelease是一种可以与依赖于编译器的内存或未手动提供内存的结构一起工作的功能
享受。我认为问题在于,当您点击后退按钮后,您当前的控制器将从导航堆栈中移除并解除分配,因此当alert尝试调用其委托方法时,它会在解除分配的对象上调用它们,这会导致
EXC\u BAD\u ACCESS
错误。要解决此问题,我看到两个明显的选项(尽管可能有更好的解决方案):
尝试将委托更改为零而不是self。它解决了我的问题。“尝试将委托更改为零而不是self。它解决了我的问题。”对我有效。Thanx可能是[message autorelease];您使用[message release]时出错了吗;不,我试过了。啊,我看到你编辑的。以前没有,所以我错了。我想弗拉基米尔的理论看起来很有道理。一定要看看。你是对的!Dealoc打电话来。我试过做[self.tableView retain];和[self retain];但仍然崩溃。我需要的不是左键,而是backItemButton。有什么解决方案吗?Thanx。我在leftItemButton的帮助下解决了这个问题。Thanx!
- (void)viewWillDisappear:(BOOL)animated
{
//if changes unsaved - alert reask window
if (isDirty)
{
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Save changes?"
message:@"Press YES if you want to save changes before exit, NO - other case."
delegate: self
cancelButtonTitle: @"NO"
otherButtonTitles: @"YES", nil];
[message show];
[message autorelease];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex: buttonIndex];
if([title isEqualToString: @"YES"])
{
[self saveBtnUserClick];
}
}