2

我正在使用 UITableView 制作一个清单程序,并且我设法实现了所有选择并显示复选标记。但是,当我滚动离开单元格时。复选标记消失。

我有以下代码:

- (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];

}

// 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([indexPath compare:[selectedArray objectAtIndex:i]] == NSOrderedSame){
if([selectedArray containsObject:cell]){
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
}else{
        cell.accessoryType = UITableViewCellAccessoryNone;
}
//}
if(tableView == sauceTable){
    cell.textLabel.text = [array4 objectAtIndex:indexPath.row];
}

return cell;}  

和:

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *c= [aTableView cellForRowAtIndexPath: indexPath];
c.accessoryType = UITableViewCellAccessoryCheckmark;
[selectedArray addObject: c];
}

有任何想法吗?

4

1 回答 1

1

解决了。使用 NSIndexPath 而不是 UITableViewCell 作为 selectionArray

于 2010-07-14T16:02:30.413 回答