【发布时间】:2011-03-16 10:11:05
【问题描述】:
我正在创建一个函数来跟踪截止日期。当您在截止日期表视图中选择一行时,我将 accessoryType 更改为 Checkmark。这与此代码完美配合:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Cell *selectedCell = (Cell *)[tableView cellForRowAtIndexPath: indexPath];
if (selectedCell.accessoryType == UITableViewCellAccessoryNone) {
[Deadline setDone: TRUE onIndex:indexPath.row];
selectedCell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
[Deadline setDone: FALSE onIndex:indexPath.row];
selectedCell.accessoryType = UITableViewCellAccessoryNone;
}
[tableView deselectRowAtIndexPath:indexPath animated: YES];
}
当您选择了一个表格单元格并滚动它消失时,会出现问题,当它再次出现时,accessoryType 再次为 None。
我在 cellForRowAtIndexPath 中决定附件类型的代码是:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";
Deadline *d = [self.arrDeadlines objectAtIndex:indexPath.row];
Cell *currCell = (Cell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (currCell == nil)
{
UIViewController *c = [[UIViewController alloc] initWithNibName:@"Cell" bundle:nil];
currCell = (Cell *)c.view;
[c release];
}
currCell.lblTitle.text = d.name;
currCell.accessoryType = d.done == TRUE ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
return currCell;
}
我该如何解决这个问题?
【问题讨论】:
-
1) 回滚完成后,deadline.done 返回什么值? 2) 显示更多
cellForRowAtIndexPath的代码。您如何管理单元格的出列? -
1) 即使我选择单元格然后取消选择单元格,它总是相同的,因为我无法运行 [tableView reloadData]。 2) 源码在上面更新了!
标签: iphone objective-c uitableview