【发布时间】:2011-06-14 07:06:31
【问题描述】:
我有一个表格视图,每次选择一行时都需要显示一个复选标记。 (多选)我的代码如下。我也可以取消选择一行。
- (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];
}
但我对重复使用的单元格有疑问。当我选择一个单元格时,其他地方的另一个单元格也会被选中。只有复选标记(或没有复选标记)被重用,其他细节(如行标题等)不会被重用。解决此问题的任何解决方案。提前致谢。
【问题讨论】:
-
我从 Stack Overflow 中回答的另一个问题中找到了解决方案:stackoverflow.com/questions/6023883/… 按照上面的链接。现在似乎对我来说工作正常。
标签: iphone objective-c uitableview