2013-07-18 36 views
0

我想使用复选标记作为切换开关让用户选择一捆项目,但这不能按预期工作 - 我必须点击单元格两次以切换单元格勾选打开/关闭。如果我做[tableView reloadData]而不是reloadRowsAtIndexPaths它根本不起作用。UITableViewCell使用复选标记作为切换开关

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

    if (cell.accessoryType == UITableViewCellAccessoryCheckmark) { 
     cell.accessoryType = UITableViewCellAccessoryNone;   
    } else if (cell.accessoryType == UITableViewCellAccessoryNone) { 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
    } 

    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; 
} 
+3

http://stackoverflow.com/questions/14411249/how-do-you-select-uitableview-rows-programmatically/14411866#14411866 – vikingosegundo

回答

3

您的代码更改视图属性,然后重装从模型的数据表视图。在重新加载之前,您应该更改模型数据而不是视图属性。

相关问题