我在另一张桌子里面有一张桌子。我可以毫无问题地将单元格添加到“supertable”和“subtable” - 它们将显示,滚动等。但是,当我尝试与“子表”交互时(选择其中一个文本字段进行编辑)程序崩溃。我在程序上运行了僵尸工具,它将崩溃回溯到此代码(我正在使用ARC):
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (saveTheTable == nil) saveTheTable = tableView;
static NSString *licenseCellId = @"licenseID";
UINib *nib = [UINib nibWithNibName:@"LicenseCell" bundle:nil];
[tableView registerNib:nib forCellReuseIdentifier:licenseCellId];
//This line causes the crash
LicenseCell *cell = [tableView dequeueReusableCellWithIdentifier:licenseCellId];
cell.delegate = self;
[licenseFields replaceObjectAtIndex:indexPath.row withObject:cell];
return cell;
}
负责的调用者是UITextField。似乎“subtable”正被自动释放池排放所释放。为什么会这样,我该如何解决?我尝试存储对细胞的强引用。
-Edit - 也许回溯会有所帮助
* thread #1: tid = 0x1f03, 0x017a309b libobjc.A.dylib`objc_msgSend + 15, stop reason = EXC_BAD_ACCESS (code=2, address=0x8)
frame #0: 0x017a309b libobjc.A.dylib`objc_msgSend + 15
frame #1: 0x003c7c7e UIKit`-[UITextField canBecomeFirstResponder] + 167
frame #2: 0x00405fe7 UIKit`-[UIResponder becomeFirstResponder] + 179
frame #3: 0x005e58fb UIKit`-[UITextInteractionAssistant setFirstResponderIfNecessary] + 208
frame #4: 0x005e75f8 UIKit`-[UITextInteractionAssistant oneFingerTap:] + 1989
frame #5: 0x005dfe29 UIKit`_UIGestureRecognizerSendActions + 143
frame #6: 0x005df133 UIKit`-[UIGestureRecognizer _updateGestureWithEvent:] + 379
frame #7: 0x005e03bf UIKit`-[UIGestureRecognizer _delayedUpdateGesture] + 46
frame #8: 0x005e2a21 UIKit`___UIGestureRecognizerUpdate_block_invoke_0541 + 57
frame #9: 0x005e297c UIKit`_UIGestureRecognizerApplyBlocksToArray + 277
frame #10: 0x005db3d7 UIKit`_UIGestureRecognizerUpdate + 1026
frame #11: 0x003401a2 UIKit`-[UIWindow _sendGesturesForEvent:] + 1121
frame #12: 0x00340532 UIKit`-[UIWindow sendEvent:] + 93
frame #13: 0x00326dc4 UIKit`-[UIApplication sendEvent:] + 464
frame #14: 0x0031a634 UIKit`_UIApplicationHandleEvent + 8196
frame #15: 0x01f9aef5 GraphicsServices`PurpleEventCallback + 1274
frame #16: 0x012b3195 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
frame #17: 0x01217ff2 CoreFoundation`__CFRunLoopDoSource1 + 146
frame #18: 0x012168da CoreFoundation`__CFRunLoopRun + 2218
frame #19: 0x01215d84 CoreFoundation`CFRunLoopRunSpecific + 212
frame #20: 0x01215c9b CoreFoundation`CFRunLoopRunInMode + 123
frame #21: 0x01f997d8 GraphicsServices`GSEventRunModal + 190
frame #22: 0x01f9988a GraphicsServices`GSEventRun + 103
frame #23: 0x00318626 UIKit`UIApplicationMain + 1163
frame #24: 0x0000274d trainingAttendance`main + 141 at main.m:16
frame #25: 0x000026b5 trainingAttendance`start + 53
答案 0 :(得分:0)
事实证明,就像phix23所说,问题在于registernib命令。这是新的cellForRowAtIndexPath
方法:
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (saveTheTable == nil) saveTheTable = tableView;
static NSString *licenseCellId = @"licenseID";
LicenseCell *cell = (LicenseCell *)[tableView dequeueReusableCellWithIdentifier:licenseCellId];
if( cell == nil ) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"LicenseCell" owner:self options:nil];
cell = (LicenseCell *)[nib objectAtIndex:0];
}
cell.delegate = self;
[licenseFields replaceObjectAtIndex:indexPath.row withObject:cell];
if (nibRetainer == nil) nibRetainer = [[NSMutableArray alloc] initWithObjects:cell, nil];
else [nibRetainer addObject:cell];
return cell;
}