1

別のテーブルの中にテーブルがあります。「スーパーテーブル」と「サブテーブル」の両方にセルを問題なく追加できます。セルは表示、スクロールなどが行われます。ただし、「サブテーブル」(編集するテキストフィールドの1つを選択)を操作しようとすると、プログラムが表示されます。クラッシュします。プログラムでゾンビツールを実行すると、クラッシュがこのコードにバックトレースされました(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です。「サブテーブル」は、自動リリースプールのドレインによって割り当てが解除されているようです。これはなぜで、どうすれば修正できますか?セルへの強い参照を保存してみました。

-編集-たぶんバックトレースが役立つでしょう

* 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
4

1 に答える 1

0

It turns out that, like phix23 said, the problem was with the registernib command. Here's the new cellForRowAtIndexPath method:

- (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;
}
于 2012-06-28T12:14:07.423 に答える