【问题标题】:how to i force UITableViewCell to keep its accessory我如何强制 UITableViewCell 保留其附件
【发布时间】:2016-01-22 17:30:06
【问题描述】:

这是我在 tableview cellForRowAtIndexPath 上使用的一段代码。

if ([[listOfQueOverview valueForKey:@"EXPENSEDETAILID"] containsObject:(_isDrilldown) ? cust.DETAILACCT : listOfOverview[0] ACCOUNTNUMBER) {
    [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
} else {
    [cell setAccessoryType:UITableViewCellAccessoryNone];
}

这允许我在点击单元格时切换附件。我遇到的问题是在使单元出队时,附件重置为无。如果我在该特定单元格上使用复选标记滚动,我如何强制它保留复选标记

【问题讨论】:

  • 你可以创建一个数据结构来记住应该有复选标记的索引路径。出队时,不能保证您正在重用具有特定附件类型的单元格,因此您只需要有一个结构来记住哪些索引路径应该有复选标记。

标签: ios objective-c uitableview


【解决方案1】:

您可以执行以下操作。每当用户点击复选标记来设置 UITableViewCellAccessoryCheckmark 时,将该行添加到 checkedIndices 数组中,如下所示:[checkedIndices addObject:@(indexPath.row)];

在你的课堂上:

@property (nonatomic, strong) NSMutableArray *checkedIndices;

// ....

self.checkedIndices = [@[]mutableCopy];

// ....

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"CellIdentifier";

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    if ([checkedIndices containsObject:@(indexPath.row)]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多