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

解決しました。selectionArrayにUITableViewCellの代わりにNSIndexPathを使用

于 2010-07-14T16:02:30.413 に答える