在我的应用程序中UITableView
,我使用过
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
当我滚动这张表时,我在多个单元格中得到了多个复选标记
请帮我..
在我的应用程序中UITableView
,我使用过
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
当我滚动这张表时,我在多个单元格中得到了多个复选标记
请帮我..
一般来说,细胞来自两种方式:
- (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.
}
因为您的单元格可能来自重用队列,所以它已被配置。显然,您忘记重新配置来自重用队列的那些单元格。
您可以在 tableView 的委托方法 didSelectedRowAtIndexPath 上使用此示例代码
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; [cell setSelected:YES 动画:YES]; [单元设置AccessoryType: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];