EXC_BAD_ACCESS with IBACTION(带有 IBACTION 的 EXC_BAD_ACCESS)
问题描述
我已经阅读了很多关于这个问题的信息,但我的似乎仍然有所不同.所以据我了解,EXC_BAD_ACCESS 会出现内存管理问题.
I have read a lot about this issue but mine still seems to be different somehow. So from what I understood, EXC_BAD_ACCESS occurs with memory management problems.
问题是,我的似乎 (!:)) 不在那里.问题是,我简单地在 IB 中添加了一个按钮,圆角矩形,没有图像.我将它与我在课堂上定义的 IBACTION 连接起来.顺便说一下,这个方法什么都不做(!).
The thing is, mine does not seem (! :)) to be there. The thing is, I simple added a button in IB, rounded rect, no image. The I hooked it up with an IBACTION I defined in my class. This method does nothing (!) by the way.
无论如何,只要我点击按钮,应用程序就会崩溃,并显示EXC_BAD_ACCESS".
Anyway, as soon as I click the button, the App crashes, with "EXC_BAD_ACCESS".
据我所知,我肯定不会过度发布任何东西.有什么问题?
I am surely not overreleasing anything, as far as I can see, that is. What is wrong there?
有什么线索吗?
这是我的控制台日志:
Loading program into debugger…
sharedlibrary apply-load-rules all
Program loaded.
target remote-mobile /tmp/.XcodeGDBRemote-148-79
Switching to remote-macosx protocol
mem 0x1000 0x3fffffff cache
mem 0x40000000 0xffffffff none
mem 0x00000000 0x0fff none
run
Running…
[Switching to thread 11779]
[Switching to thread 11779]
(gdb) continue
2010-01-15 09:16:34.800 FlightControl1[1899:207] Table loaded
2010-01-15 09:16:35.200 FlightControl1[1899:207] 23
2010-01-15 09:16:35.350 FlightControl1[1899:207] debug
Program received signal: "EXC_BAD_ACCESS".
(gdb)
这是我上栈后得到的:
#0 0x31ec3ebc in objc_msgSend ()
#1 0x33605784 in -[UIApplication sendAction:to:from:forEvent:] ()
#2 0x336056ec in -[UIApplication sendAction:toTarget:fromSender:forEvent:] ()
#3 0x336056b4 in -[UIControl sendAction:to:forEvent:] ()
#4 0x3360530c in -[UIControl(Internal) _sendActionsForEvents:withEvent:] ()
#5 0x33605f8c in -[UIControl touchesEnded:withEvent:] ()
#6 0x335fd9ac in _UIGestureRecognizerUpdateObserver ()
#7 0x30da1830 in __CFRunLoopDoObservers ()
#8 0x30de9346 in CFRunLoopRunSpecific ()
#9 0x30de8c1e in CFRunLoopRunInMode ()
#10 0x332e7374 in GSEventRunModal ()
#11 0x335adc30 in -[UIApplication _run] ()
#12 0x335ac230 in UIApplicationMain ()
#13 0x000027a8 in main (argc=1, argv=0x2ffff4d8) at /Users/SomePath/main.m:14
推荐答案
我也被这个折磨了几个小时.正如预期的那样,结果是内存问题.作为按钮目标的控制器已被释放.它是导航控制器的根控制器,其视图直接添加到窗口中.我的代码如下所示:
I was tortured by this for a few hours as well. It turned out to be a memory problem as expected. The controller acting as the target for the button was deallocated. It was the root controller of a navigation controller whose view was added directly to the window. My code looked like this:
MyController *myController = [[MyController new] autorelease];
UINavigationController* navController =
[[[UINavigationController alloc] initWithRootViewController:myController] autorelease];
[window addSubview:navController.view];
我的假设是 myController
在作为 UINavigationController
的根控制器传递时会被保留,但结果证明这是错误的.解决方案是将控制器分配给一个局部变量并在 dealloc
中释放它.包含上述代码的对象的接口应该有:
My assumption was that myController
would be retained when it's passed as the root controller of the UINavigationController
, but that turned out to be wrong. The solution was to assign the controller to a local variable and release it in dealloc
. The interface of the object containing the above code should have:
...
@property (retain, nonatomic) MyController *myController;
...
以及实现:
self.myController = [[MyController new] autorelease];
UINavigationController* navController =
[[[UINavigationController alloc] initWithRootViewController:myController] autorelease];
[window addSubview:navController.view];
...
- (void)dealloc {
[self.myController release];
...
[super dealloc];
}
这篇关于带有 IBACTION 的 EXC_BAD_ACCESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:带有 IBACTION 的 EXC_BAD_ACCESS
- GPS状态的广播接收器? 2022-01-01
- UITextView 内容插图 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- URL编码Swift iOS 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01