UIbutton 在自定义 UITableViewCell 中释放

发布于 2024-12-12 22:24:44 字数 1856 浏览 0 评论 0原文

使用 ARC(自动引用计数),我在子类 UITableViewCell 中有一个 UIButton。表视图控制器实现了连接到UIButtonIBAction。在子类单元的 xib 中,相同的表视图控制器是文件的所有者。

当我运行应用程序并单击按钮时出现问题,我收到 EXC_BAD_ACCESS。它在 iPhone 屏幕上清晰可见,因此它在某个时刻被分配。

知道问题出在哪里吗?提前致谢!

编辑1:
注意:我将环境变量 NSZombieEnabled 设置为 true。 这是控制台:

2011-10-31 22:22:08.653 MyApp[7176:fb03] *** -[NSObject performSelector:withObject:withObject:]: message sent to deallocated instance 0x6b94d40
(lldb) thread backtrace
* thread #1: tid = 0x1f03, 0x014c3e1e CoreFoundation`___forwarding___ + 206, stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
frame #0: 0x014c3e1e CoreFoundation`___forwarding___ + 206
frame #1: 0x014c3ce2 CoreFoundation`_CF_forwarding_prep_0 + 50
frame #2: 0x001e45c2 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 96
frame #3: 0x001e455a UIKit`-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
frame #4: 0x00289b76 UIKit`-[UIControl sendAction:to:forEvent:] + 66
frame #5: 0x0028a03f UIKit`-[UIControl(Internal) _sendActionsForEvents:withEvent:] + 503
frame #6: 0x002892fe UIKit`-[UIControl touchesEnded:withEvent:] + 549
frame #7: 0x004a2a2a UIKit`_UIGestureRecognizerUpdate + 6725
frame #8: 0x015319ce CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
frame #9: 0x014c8670 CoreFoundation`__CFRunLoopDoObservers + 384
frame #10: 0x014944f6 CoreFoundation`__CFRunLoopRun + 1174
frame #11: 0x01493db4 CoreFoundation`CFRunLoopRunSpecific + 212
frame #12: 0x01493ccb CoreFoundation`CFRunLoopRunInMode + 123
frame #13: 0x02449879 GraphicsServices`GSEventRunModal + 207
frame #14: 0x0244993e GraphicsServices`GSEventRun + 114
frame #15: 0x001e1a9b UIKit`UIApplicationMain + 1175
frame #16: 0x0000278d MyApp`main + 125 at main.m:14
frame #17: 0x00001ff5 MyApp`start + 53

Using ARC (Automatic Reference Counting), I have a UIButton in a subclassed UITableViewCell. The table view controller implements the IBAction which is hooked up to the UIButton. In the subclassed cell's xib, the same table view controller is the File's Owner.

The problem occurs when I run the app and click on the button, I get an EXC_BAD_ACCESS. It's clearly visible on the iPhone screen, so it is being allocated at some point.

Any idea what the problem could be? Thanks in advance!

EDIT1:
Note: I have env variable NSZombieEnabled set to true.
Here's the console:

2011-10-31 22:22:08.653 MyApp[7176:fb03] *** -[NSObject performSelector:withObject:withObject:]: message sent to deallocated instance 0x6b94d40
(lldb) thread backtrace
* thread #1: tid = 0x1f03, 0x014c3e1e CoreFoundation`___forwarding___ + 206, stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
frame #0: 0x014c3e1e CoreFoundation`___forwarding___ + 206
frame #1: 0x014c3ce2 CoreFoundation`_CF_forwarding_prep_0 + 50
frame #2: 0x001e45c2 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 96
frame #3: 0x001e455a UIKit`-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
frame #4: 0x00289b76 UIKit`-[UIControl sendAction:to:forEvent:] + 66
frame #5: 0x0028a03f UIKit`-[UIControl(Internal) _sendActionsForEvents:withEvent:] + 503
frame #6: 0x002892fe UIKit`-[UIControl touchesEnded:withEvent:] + 549
frame #7: 0x004a2a2a UIKit`_UIGestureRecognizerUpdate + 6725
frame #8: 0x015319ce CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
frame #9: 0x014c8670 CoreFoundation`__CFRunLoopDoObservers + 384
frame #10: 0x014944f6 CoreFoundation`__CFRunLoopRun + 1174
frame #11: 0x01493db4 CoreFoundation`CFRunLoopRunSpecific + 212
frame #12: 0x01493ccb CoreFoundation`CFRunLoopRunInMode + 123
frame #13: 0x02449879 GraphicsServices`GSEventRunModal + 207
frame #14: 0x0244993e GraphicsServices`GSEventRun + 114
frame #15: 0x001e1a9b UIKit`UIApplicationMain + 1175
frame #16: 0x0000278d MyApp`main + 125 at main.m:14
frame #17: 0x00001ff5 MyApp`start + 53

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧城烟雨 2024-12-19 22:24:44

想通了。我使用 UINibinstantiateWithOwner: options: 加载自定义 UITableViewCell 的笔尖。我将所有者设置为nil。将所有者设置为我的视图控制器修复了它。另外,我的视图控制器是该 UITableViewCell 笔尖的文件所有者。我猜测是因为视图控制器和笔尖没有正确链接,ARC 没有看到保留视图的理由。

Figured it out. I was using UINib's instantiateWithOwner: options: to load the nib of the custom UITableViewCell. I was setting the owner to nil. Setting the owner to my view controller fixed it. Also, my view controller is the File's Owner of that UITableViewCell nib. I'm guessing because the view controller and nib were not properly linked, ARC did not see a reason to keep the view around.

雾里花 2024-12-19 22:24:44

我不确定,但我感觉你的问题出在你传递给按钮的选择器上。

尝试查看是否对不带参数的方法使用带有“:”的选择器。

如果您使用的选择器如下所示:

@selector(method:)

那么预计“方法”将采用参数:

-(IBAction)method:(UIButton)sender{
}

如果您的函数不采用任何参数:

-(IBAction)method{
}

那么您的选择器应如下所示:

@selector(method)

I am not sure but I have a feeling your problem is in the selector you are passing to the button.

Try to see if you are using a selector with ":" to a method with out parameters.

If you are using selector that looks like this:

@selector(method:)

Then is is expected that "method" will take parameters:

-(IBAction)method:(UIButton)sender{
}

if your function is not taking any parameters:

-(IBAction)method{
}

then your selector should look like that:

@selector(method)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文