0

下の図のようなテーブル ビューがあります。

セクション不在で表の行を選択するときに、チェック ボックスを変更し、マーク チェック ボックスを使用したい

私はこのメソッドを使用する必要があることを知っています didSelectRowAtIndexPath: 「ユーザーが行を選択すると、画像が変更されるはずです」

助けてくれませんか

前もって感謝します!

ここに私のコードがあります:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *key = [[self sectionKeys] objectAtIndex:[indexPath section]];
NSArray *contents = [[self sectionContents] objectForKey:key];
NSString *contentForThisRow = [contents objectAtIndex:[indexPath row]];

if (indexPath.section != 2) {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    cell.textLabel.text =contentForThisRow;
    return cell;
}
else {
    CheckBoxCompensationViewCell *cell = (CheckBoxCompensationViewCell*)[tableView 
dequeueReusableCellWithIdentifier:@"CheckBoxCompensationViewCell"];

    cell.imageView.image=[UIImage imageNamed:@"emptycheck-box.png"];
    cell.checkBox.image = image;
    if(indexPath.row == 0){
        cell.compensationText.text =@"Red";
    }
    else if (indexPath.row == 1){
        cell.compensationText.text =@"Green";

    }else if(indexPath.row == 2){
        cell.compensationText.text =@"Blue";
    }
    return cell;
}
}



 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
// I don't know what should I have here , probably mark box image but I don't know how
}
4

2 に答える 2

2
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSIndexPath *previousPath = self.selectedIndexPath;
    self.selectedIndexPath = indexPath;
    [tableView reloadRowsAtIndexPaths:@[previousPath, indexPath] withRowAnimation:UITableViewRowAnimationNone];
}

これは非常に基本的なものであり、セルの選択を解除しないことに注意してください。cellForRowAtIndexPath で選択したインデックス パスの状態を確認する必要があります。

于 2012-08-08T14:26:16.237 に答える
0

非常に簡単。ユーザーがセルを選択したら、データ モデルを更新してテーブルをリロードする必要があります。データモデルはボタンの状態を保存します。cellForRowAtIndexPath メソッドでは、データ モデルの状態に応じてボタンを設定します。それで全部です。

于 2012-08-08T14:28:05.173 に答える