Ick*_*cky 24 iphone exc-bad-access uibutton
我已经阅读了很多关于这个问题的内容,但我似乎仍然有所不同.所以根据我的理解,EXC_BAD_ACCESS会出现内存管理问题.
事情是,我的似乎不是(!:)).问题是,我简单地在IB中添加了一个按钮,圆角矩形,没有图像.我把它与我班上定义的IBACTION联系在一起.顺便说一句,这个方法什么都不做(!).
无论如何,只要我点击按钮,应用程序崩溃就会出现"EXC_BAD_ACCESS".
就我所知,我肯定不会过度释放任何东西.有什么问题?
有线索吗?
这是我的控制台日志:
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)
Run Code Online (Sandbox Code Playgroud)
在我上堆栈之后,这就是我得到的:
#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
Run Code Online (Sandbox Code Playgroud)
小智 53
我被这个折磨了几个小时.事实证明这是一个预期的记忆问题.作为按钮目标的控制器被取消分配.它是导航控制器的根控制器,其视图直接添加到窗口中.我的代码看起来像这样:
MyController *myController = [[MyController new] autorelease];
UINavigationController* navController =
[[[UINavigationController alloc] initWithRootViewController:myController] autorelease];
[window addSubview:navController.view];
Run Code Online (Sandbox Code Playgroud)
我的假设是myController当它作为根管理器传递时会保留UINavigationController,但结果证明是错误的.解决方案是将控制器分配给局部变量并将其释放dealloc.包含上述代码的对象的接口应该具有:
...
@property (retain, nonatomic) MyController *myController;
...
Run Code Online (Sandbox Code Playgroud)
并实施:
self.myController = [[MyController new] autorelease];
UINavigationController* navController =
[[[UINavigationController alloc] initWithRootViewController:myController] autorelease];
[window addSubview:navController.view];
...
- (void)dealloc {
[self.myController release];
...
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11308 次 |
| 最近记录: |