2

セルを透明にする方法を教えてください。選択したセルにチェックマークを付けて表示したいだけです:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];

    if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
        cell.accessoryType = UITableViewCellAccessoryNone;
    } 
    else {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
}

そして、最初にセルを作成するときに、次のコード行を実行して青い背景を取り除きます

cell.selectionStyle = UITableViewCellSelectionStyleNone;

しかし、チェックボックスを追加および削除するのに2回のクリックが必要であるという奇妙な問題があります。たぶん、これは正しい方法ではありませんか?

4

1 に答える 1

1

ここで透明にすることについて読むことができますUITableViewCell: How to create a UITableViewCell with a transparent background

そして、あなたの2番目の問題に関しては、これがおそらくあなたが実際に望んでいることのようです:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)path {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
    cell.accessoryType = UITableViewCellAccessoryNone;
}
于 2013-04-08T21:12:36.997 に答える