开发者

table cell indicater problem

in my application I have UITableView & i used

[cell setAccessoryType:UITableViewCellAccessoryCheckmark];

and when I scrolled this table then I get multiple开发者_开发知识库 checkmark in multiple cell

please help me..


In general, the cell come from 2 ways:

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

  static NSString *identifier = @"Cell";
  UITableViewCell *cell = ... // The cell come from reuse queue.
  if (cell == nil) {
      cell = ... // if reuse queue has no cell, then create an autoreleased cell
  } 

  // Configure cell by indexPath.
  // You should configure cell HERE.

}

Because your cell maybe come from reuse queue, it was configured. Obviously, you forget to re-configure those cells which come from reuse queue.


you can use this sample code on tableView's delegate method didSelectedRowAtIndexPath

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; [cell setSelected:YES animated:YES]; [cell setAccessoryType:UITableViewCellAccessoryCheckmark];

    for(int iterator=0;iterator<3;iterator++)
    {

        UITableViewCell *eachCell = [[self tableView] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:iterator inSection:0]];
        [eachCell setSelected:NO animated:YES];
        [eachCell setAccessoryType:UITableViewCellAccessoryNone];
    }

    UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
    [newCell setSelected:YES animated:YES];
    [newCell setAccessoryType:UITableViewCellAccessoryCheckmark];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜