2012-07-15 31 views
2

说我有一个小的tableview(不滚动),当用户点击一个选项时,它会改变应用程序中的一些设置。我用这个功能:如何在UITableViewCell中添加复选标记

- (void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
     //some code here 
} 

现在我想用UITableViewCellAccessoryCheckmark对于被选择的选项,我的意思是它应该显示在用户选择的单元复选标记(从以前选择的选项删除标记)。我怎么做?

回答

8

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; 
{ 
    for (UITableViewCell *cell in [tableView visibleCells]) { 
    cell.accessoryType = UITableViewCellAccessoryNone; 
    } 

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    cell.accessoryType = UITableViewCellAccessoryCheckmark; 
} 
+0

男人!这解决了问题!这是一种很棒的迭代方式,我不知道可以做到这一点。多谢! – 2012-07-15 09:14:23

0

只需使用UITableViewCellaccessoryType财产。

@property(nonatomic) UITableViewCellAccessoryType accessoryType 

像这样:

- (void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

     //code for reusing or init a new cell goes here 

     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
} 
+0

感谢的人如何对多数民众赞成这样做的一种方式......你可以帮我一个小东西......看我的评论以上答案。谢谢。 – 2012-07-15 08:40:05

相关问题