【发布时间】:2010-07-13 19:42:17
【问题描述】:
我有这个奇怪的问题。我正在使用 XCode 制作一个清单程序,并且正在使用 UITableView 和 UITableViewCellAccessoryCheckmark。我可以选择单元格并出现复选标记,但不知何故,我尚未在下面选择的其他单元格也会出现复选标记。有什么想法吗?
这是我的复选标记编码:
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
cell = [aTableView cellForRowAtIndexPath: indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
不知道有没有影响,不过我也实现了这个方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CellIdentifier";
// Dequeue or create a cell of the appropriate type.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
}
// Configure the cell.
if(tableView == Table1){
switch(indexPath.section){
case 0:
cell.textLabel.text = [array1 objectAtIndex:indexPath.row];
break;
case 1:
cell.textLabel.text = [array2 objectAtIndex:indexPath.row];
break;
case 2:
cell.textLabel.text = [array3 objectAtIndex:indexPath.row];
break;
}
//cell.textLabel.text = [NSString stringWithFormat:@"Row %d", indexPath.row];
}
if(tableView == Table2){
cell.textLabel.text = [array4 objectAtIndex:indexPath.row];
}
return cell;
}
谢谢。
【问题讨论】:
-
你能分享一下你对
tableView:cellForRowAtIndexPath:的实现吗? -
我同意 Prairiedogg,让我们看看其余的代码。您可能会重复使用单元格,因此不会重置它们的状态。
标签: iphone objective-c xcode uitableview