我有一个tableview,我需要每次选择一行时显示一个复选标记。 (多选)我的代码如下。我也能够取消选择一行。问题:正在重用多个选择tableview单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *RootViewControllerCell = @"RootViewControllerCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:RootViewControllerCell];
if(nil == cell)
{
cell = [[[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:RootViewControllerCell] autorelease];
}
cell.textLabel.font = [UIFont fontWithName:[NSString stringWithFormat:@"HelveticaNeue-Bold"] size:12];
textView.textColor = [UIColor colorWithRed:0.281 green:0.731 blue:0.8789 alpha:1];
cell.textLabel.text = [optionsArray objectAtIndex:[indexPath row]];
if (pathIndex == indexPath)
{
if (cell.accessoryType == UITableViewCellAccessoryCheckmark)
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
pathIndex = indexPath;
[surveytableView reloadData];
}
但我有一个单元格被重用的问题。当我选择一个单元另一个单元其他地方也被选中。只有复选标记(或没有复选标记)才会被重用,其他细节(如行标题等)不会被重用。任何解决方案来解决这个提前致谢。
我发现从堆栈溢出回答另一个问题一个解决方案: http://stackoverflow.com/questions/6023883/ uitableview-multiple-checkmark-selection Folllow this above link。似乎现在对我来说工作得很好。 – 2011-06-14 07:33:29