繁体   English   中英

UITableViewCell删除和保存单元格时泄漏

[英]UITableViewCell Leak when deleting and saving the cell

我注意到我的自定义UITableViewCell之一正在泄漏。 在执行编辑时不会释放它,请删除底部的单元格并点击“保存”。 这是我在表格中的顶部单元格(我称之为添加单元格)。 表格视图进入编辑模式后,将显示“添加”单元格,同时在“删除”模式下显示所有其他单元格。 现在,执行删除操作并保存数据后,即使调用了我的表视图上的dealloc,Add Cell仍然会徘徊。

我正在附上我的代码和乐器屏幕截图(我从屏幕截图中删除了第一行(Malloc调用)。对我来说,iOS内部处理似乎有问题。请告知。)

- (UITableViewCell *)tableView:(UITableView *)iTableView cellForRowAtIndexPath:(NSIndexPath *)iIndexPath {
    MyTableViewCell *aCell = nil;
    NSString *aCellType;

    if (iIndexPath.row == 0 && self.inEditMode) {
        aCellType = kMyAddCell;
        aCell = (MyAddCell *)[iTableView dequeueReusableCellWithIdentifier:aCellType];

        if (!aCell) {
            aCell = [[MyAddCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:aCellType];
        }

        aCell.isGroupedView = YES;
        aCell.delegate = self;
        aCell.textLabel.text = @“Add More";
        self.tableView.allowsSelectionDuringEditing = YES;
    } else {
        aCellType = kMyDefaultCell;
        aCell = (MyTableViewCell *)[iTableView dequeueReusableCellWithIdentifier:aCellType];

        if (!aCell) {
            aCell = [[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:aCellType];
        }

        NSInteger anIndex = iIndexPath.row;

        if (self.inEditMode) {
            anIndex = anIndex - 1;
        }

        aCell.textLabel.text = @“Name";
        aCell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    return aCell;
}


- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)iIndexPath {
    return (iIndexPath.row == 0 && self.inEditMode) ? UITableViewCellEditingStyleNone : UITableViewCellEditingStyleDelete;
}


- (BOOL)tableView:(UITableView *)iTableView canEditRowAtIndexPath:(NSIndexPath *)iIndexPath {
    return YES;
}


- (void)tableView:(UITableView *)iTableView commitEditingStyle:(UITableViewCellEditingStyle)iEditingStyle forRowAtIndexPath:(NSIndexPath *)iIndexPath {
    if (iEditingStyle == UITableViewCellEditingStyleDelete) {
    [self setSaveModeNavigationBar];
        [self.tableView beginUpdates];
        [self.enabledUsers removeObjectAtIndex:(self.inEditMode) ? iIndexPath.row - 1 : iIndexPath.row];
        [self.tableView deleteRowsAtIndexPaths:@[iIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.tableView endUpdates];
    }
}


- (void)setEditing:(BOOL)iEditing animated:(BOOL)iAnimated {
    [super setEditing:iEditing animated:iAnimated];
    [self.navigationItem setHidesBackButton:YES animated:NO];

    self.headerViewLabel.text = @“Edit Me";

    UIBarButtonItem *aDoneButton = [[UIBarButtonItem alloc] initWithTitle:@“Done"
                                                                    style:UIBarButtonItemStylePlain
                                                                   target:self
                                                                   action:@selector(cancelEditing)];
    [self.navigationItem setRightBarButtonItem:aDoneButton];
    [self.navigationItem setLeftBarButtonItem:nil animated:YES];
    self.inEditMode = YES;
    [self.tableView reloadData];
}

我点击“保存”按钮后即会调用的代码:

    self.requestHandler = [[MyRequestHandler alloc] initWithEndPoint:myEndPoint body:aPostBody successHandler:^(NSDictionary *iResponse) {
        [aBlockSelf addNoDataOverlay];
    } andErrorHandler:^(NSString *iMessage, NSString *iKey, NSInteger iErrorCode, BOOL iIsNetworkError) {
        [aBlockSelf addNoDataOverlay];
    }];

[self.requestHandler executeRequest];

仪器分配栈:

在此处输入图片说明

显然,这是在此线程中跟踪的已知问题。 在iPhone 5S(iOS 8)中尝试了相同的步骤,并在那里解决了问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM