- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在向用户显示一个 UIAlertView
,上面有一个“确定”按钮,当用户按下按钮时,我希望我的委托(delegate)方法执行一个操作。然而,目前当用户按下“确定”按钮时,应用程序崩溃并出现此错误:
Thread 1: EXC_BAD_ACCESS (code=1, address=0xb)
这是我的代码,警报 View 通过按钮等显示正常,但是一旦按下按钮,这就是我收到的错误。这几乎就像一个断点,但如果我点击前进按钮,什么也不会发生。
//.h
@interface ErrorHandling : NSObject <UIAlertViewDelegate> {
//.m
#define myAlertViewsTag 0
- (void)recivedErrorCode:(int)errorCode MethodName:(NSString *)methodName {
switch (errorCode) {
case 1: {
NSLog(@"ERROR = 1");
message = [[UIAlertView alloc] initWithTitle:@"Error 1:"
message:@"The supplied registration code does exist."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[SVProgressHUD dismiss];
[message show];
}
break;
case 2: {
NSLog(@"ERROR = 2");
message = [[UIAlertView alloc] initWithTitle:@"Error 2:"
message:@"Your registration is no longer valid."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
message.tag = myAlertViewsTag;
[SVProgressHUD dismiss];
[message show];
}
break;
default:
break;
}
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (message.tag == myAlertViewsTag) {
if (buttonIndex == 0) {
// Do something when ok pressed
NSLog(@"DONE 1");
} else {
// Do something for ok
NSLog(@"DONE 2");
}
} else {
// Do something with responses from other alertViews
NSLog(@"DONE 3");
}
}
更新:这就是我从我的连接类中调用上面代码所在的类的方式。
// Do whatever you need to with the error number
ErrorHandling *errorHandling = [[ErrorHandling alloc] init];
[errorHandling recivedErrorCode:errorRecivedFromServerInt MethodName:methodName];
最佳答案
问题在于您的 ErrorHandling
实例的生命周期。您创建一个实例,然后调用 recivedErrorCode:
方法。在那之后没有其他对您的 errorHandling
实例的强引用,因此它被释放。
与此同时,警报 View 已将实例作为其委托(delegate)。当您点击警报 View 上的按钮时,警报 View 会尝试联系其代理。但委托(delegate)已被释放,现在指向导致崩溃的垃圾内存。
解决方案是对 ErrorHandling
实例保持更持久的强引用。至少在关闭警报 View 之前。
顺便说一句 - 您的方法名称有错字 - 它应该是 receivedErrorCode:
。
关于ios - 导致错误的 UIAlertView 按钮操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18177597/
这个问题已经有答案了: iOS How to dismiss UIAlertView with one tap anywhere? (2 个回答) 已关闭10 年前。 嗨,我是 Xcode 新手,ob
我试图在我的 swift 应用程序中显示一个 UIAlertView alert = UIAlertView(title: "", message: "bla",
问题是 iOS 键盘有时不再有反应。所以没有输入是可能的。如果我取消注释 clickedButtonAtIndex 中的第二个 UIAlertView,它工作正常。 原因可能在其他地方?我不知道...
我是 iPhone 开发人员的新人, 我想依次实现2个警报 View ,就像当用户按下删除按钮时,第一个警报 View 会询问你确定要删除吗?有两个按钮是 和否 现在,如果用户按 yes ,则第二个警
我想弄清楚为什么我的应用程序会崩溃。 它在带有 ios5.1 的模拟器中运行的 Xcode 4.4 中运行良好,但是当我切换到 xcode 4.5 和 ios6 时,我得到了 EXC_BAD_ACCE
我的 iOS 应用程序正在使用 Swift 2.0、RMUniversalAlert 版本 0.7 和 UIAlertView+Blocks 版本 0.9 当我在 Xcode 7 中构建它时,出现错误
我遇到了崩溃: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-
我在主线程上显示 UIAlertView 时遇到问题。我不知道为什么,但它不断崩溃,尽管我在主线程上运行。以下 block 位于后台线程上,但我在主线程上有警报,如下所示: void (^remove
我已将 iPhone 设置为横向模式,但当我尝试显示 UIAlertView 时,它会进入纵向模式。横向模式下如何显示? 最佳答案 在applicationDelegate.m文件的applicati
我使用 UIAlerView 子类创建自定义登录页面。现在,当我单击按钮时,它会打开 UIAlertView 我想根据按下的按钮更改主视图。 但是,由于 UIAlerView 的所有实现都在另一个类中
我弹出一个 UIAlertView 来询问用户是否确实要打开某个 URL。如果他们选择"is",我的应用程序会立即打开 URL 并发送到后台。当用户重新打开我的应用程序(使用多任务处理)时,警报 Vi
有没有办法将 .tag 添加到 UIAlertView 按钮?原因是,我向警报添加了一些动态按钮,这些按钮有时会出现在警报中,有时不会。我认为最好的方法是添加标签。有更好的方法吗? 警报中始终出现的选
我在 ib 中创建了一个自定义 uialertview,带有两个按钮和一个文本字段。然后我以这种方式创建一个 .h 和一个 .m: #import @interface DialogWelcome
看一下下面的代码,问题是AlertView没有显示出来,即使我在调试中看到代码已被执行。 请指教。 非常感谢 埃兰 -(void)displayABC:(id)sender { sta
我正在尝试更改 uialertview 的背景。一切工作正常,除了我添加到 uialert View 的背景图像不会在警报 View 内缩放。所以基本上你只能看到基于当前大小的背景图像的一部分。有什么
在我的应用程序中,我使用验证 key 通过 Wi-Fi 从服务器下载内容。如果许可证 key 错误或 wi-fi 不可用,我需要显示 UIAlert。我已经编写了用于显示警报 View 的男女混合代码
我创建了一个带有两个按钮和一个文本字段的 uialertview,如果文本字段为空,我希望禁用“确定”按钮。我如何获取 uibutton 对象来更改启用状态。 最佳答案 您可以使用从 UIContro
iPhone 应用程序开发人员您好, 我正在开发一个 iPhone 应用程序。该应用程序允许用户将图像上传到我的服务器。我想在alertView中显示上传进度。我需要一些示例代码来说明如何实现带有进度
有没有办法以编程方式隐藏 UIAlertView。我正在我的进度 View 中显示进度 View ,当进度 View = 1.0 时,我想隐藏 UIAlertView。 最佳答案 您可以做的是观察(使
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: Is it possible to lay out 2 buttons vertically on UIAlertV
我是一名优秀的程序员,十分优秀!