2016-01-22 40 views
0

以下是我在桌面视图cellForRowAtIndexPath上使用的一段代码。如何强制UITableViewCell保留其附件

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

这允许我点击单元时切换附件。我有的问题是,当一个细胞出队时,配件重置为零。我如何强制它保持复选标记,如果我滚动与该特定单元格上的复选标记

+0

你可以创建记得应该有索引路径的数据结构复选标记。出队时,您无法保证您重复使用具有特定附件类型的单元格,因此您只需拥有一个可记住哪些索引路径应该有复选标记的结构。 –

回答

0

您可以执行以下操作。每当用户点击勾选设置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; 
    } 
} 
+0

这个伎俩,谢谢 – highboi