iOS开始向下滚动时复选标记消失

iOS开始向下滚动时复选标记消失

问题描述:

开始向下滚动时复选标记消失的方式。iOS开始向下滚动时复选标记消失

继承人的didSelectRowAtIndexPath方法的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; 

    if (selectedCell.accessoryType == UITableViewCellAccessoryCheckmark) { 
     selectedCell.accessoryType = UITableViewCellAccessoryNone; 

     if ([[[collectionDataArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"creditHours"][email protected]"1") { 
      totalHoure = totalHoure - 1; 
     } 

    } else { 

     selectedCell.accessoryType = UITableViewCellAccessoryCheckmark; 

     if ([[[collectionDataArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"creditHours"][email protected]"1") { 
      totalHoure = totalHoure + 1 ; 
     } 
    } 
} 

有什么问题吗?或者是否有其他技术。

+0

显示你在**'viewWillAppear中有代码:'**。 'didSelectRowAtIndexPath'与滚动无关。另外,你应该在'cellForRowAtIndexPath'中分配对号附件。如果要切换复选标记,请将'reloadData'放在'didSelectRowAtIndexPath'中。 – WrightsCS 2012-07-12 23:57:07

试试这个存储对号细胞data.And希望这能解决你的问题:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
     UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; 

     if ([selectedCell accessoryType] == UITableViewCellAccessoryNone || [selectedCell accessoryType]== UITableViewCellAccessoryDisclosureIndicator) 
     { 
      [selectedCell setAccessoryType:UITableViewCellAccessoryCheckmark]; 
        [Mybuffer addObject:[arrItem objectAtIndex:indexPath.row]]; 
     } 
     else 
     { 
      [selectedCell setAccessoryType:UITableViewCellAccessoryNone]; 
      [Mybuffer removeObject:[NSNumber numberWithInt:indexPath.row]]; 
     } 
} 
+0

请格式化一下代码,使其更具可读性。另外,你能否在一两行中解释它的作用? – 2014-07-02 06:54:01

确保将复选标记存储在模型的某处。随着用户滚动UITableView,单元格随即重新创建。然后确保在tableView:cellForRowAtIndexPath:中正确地重新设置复选标记。