2013-07-22 56 views
-2

我写过一个程序,它将一组对象存储在一个标签下,并且可以稍后查看和更改标签。我已经写了下面的代码(仅包括添加复选标记的部分):复选标记未出现在UITableView中

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

cell.selectionStyle = UITableViewCellSelectionStyleNone; //To avoid the blue selection 
//necessary codes to populate the table here 
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark; 
return cell; 
} 

但是表格甚至没有显示任何复选标记。是的,我通过评论cell.selectionStyle = UITableViewCellSelectionStyleNone;再次尝试,仍然没有用。我没有在其他地方编写任何代码来取消选中已选中的复选标记。

+2

尝试cell.accessoryType = UITableViewCellAccessoryCheckmark; – Girish

+0

你在那里有无限的递归。 – Fogmeister

+0

无限递归?怎么样? –

回答

3

你为什么要设置附件类型这样 [tableView cellForRowAtIndexPath:indexPath].accessoryType,因为你所得到的细胞本身在这个方法中

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; //To avoid the blue selection 
     //necessary codes to populate the table here 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; //Do like this 
     return cell; 
} 


1

更换

[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark; 

cell.accessoryType = UITableViewCellAccessoryCheckmark; 
1

要对号出现使用

cell.accessoryType = UITableViewCellAccessoryCheckmark; 
相关问题