UITextField 捕获 textFieldDidBeginEditing 事件会导致 main.m 中的 EXC_BAD_ACCESS
这很神秘。
我的视图控制器在 .h 文件中实现了 UITextFieldDelegate 协议,在 .mm 文件中,我有
myTextField.delegate = self
我的 textFieldDidBeginEditing 事件只是一条 NSLog 消息。
当我运行程序并将焦点设置在 myTextField 上时,出现 EXC_BAD_ACCESS 错误。
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil); // EXC_BAD_ACCESS
[pool release];
return retVal;
}
这肯定是我在某个地方犯了一个明显的错误,但它已经困扰了我一整夜。有人知道为什么吗?我如何捕获文本字段的开始编辑事件?
This is mystifying.
My view controller implements the UITextFieldDelegate protocol in the .h file, and in the .mm file, I have
myTextField.delegate = self
And my textFieldDidBeginEditing event is simply a NSLog message.
When I run my program and set focus on myTextField, I get a EXC_BAD_ACCESS error.
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil); // EXC_BAD_ACCESS
[pool release];
return retVal;
}
It must be an obvious blunder I have somewhere, but it's been troubling me all night. Anybody knows why? And how I can catch the begin-edit event of a textField?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,Xcode 4 改变了调试器的行为。在左侧的调试器面板上,底部应该有一个滑块 - 显示更多或更少的堆栈帧。您正在显示顶部堆栈框架(UIApplication)——如果您滑动该滑块,您很可能会更清楚地了解崩溃的位置。
另外,如果是 EXC_BAD_ACCESS,您是否打开 NSZombieEnabled = YES 作为环境变量来捕获过度释放的内容?通常是内存问题。
Foremost, Xcode 4 changed the behavior of the debugger. On the debugger panel on the left, there should be a slider all the way at the bottom - showing you MORE or LESS stack frames. You're showing the top stack frame (UIApplication) -- chances are if you slide that slider you'll see more of an idea of where you are crashing.
Also, if it's EXC_BAD_ACCESS, have you turned on NSZombieEnabled = YES as an environment variable to catch what is being over-released? Usually it's a memory problem.