簡體   English   中英

UIbutton在自定義UITableViewCell中釋放

[英]UIbutton deallocated in custom UITableViewCell

使用ARC(自動引用計數),我在子類UITableViewCell有一個UIButton。 表視圖控制器實現連接到UIButtonIBAction 在子類化單元的xib中,同一個表視圖控制器是文件的所有者。

當我運行應用程序並單擊按鈕時出現問題,我得到一個EXC_BAD_ACCESS 它在iPhone屏幕上清晰可見,因此它在某些時候被分配。

知道問題可能是什么? 提前致謝!

EDIT1:
注意:我將env變量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

弄清楚了。 我正在使用UINibinstantiateWithOwner: options:加載自定義UITableViewCell的nib。 我把主人設置nil 將所有者設置為我的視圖控制器修復它。 此外,我的視圖控制器是該UITableViewCell筆尖的File's Owner 我猜是因為視圖控制器和筆尖沒有正確鏈接,ARC沒有看到保持視圖的理由。

我不確定,但我感覺你的問題出現在你傳遞給按鈕的選擇器中。

嘗試查看是否使用帶有“:”的選擇器來指定帶參數的方法。

如果您使用的選擇器如下所示:

@selector(method:)

然后是預期“方法”將采取參數:

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

如果你的功能沒有采取任何參數:

-(IBAction)method{
}

那么你的選擇器應該是這樣的:

@selector(method)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM