Skip to content

Instantly share code, notes, and snippets.

@nantekkotai
Created July 13, 2012 10:21
Show Gist options
  • Save nantekkotai/3104096 to your computer and use it in GitHub Desktop.
Save nantekkotai/3104096 to your computer and use it in GitHub Desktop.
UITableViewの編集モードの時にアクセサリを変更するには

カスタムセルを作ってごにゃごにゃやるのかと思ったら、すごく簡単だった。
要は編集モード用のAccessoryTypeがあるのです。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    
    cell.textLabel.text = @"テスト";
    // 標準時はインディケータ
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    // 編集モード時はボタン
    cell.editingAccessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    
    return cell;
}

これで編集モードに変更すれば、スルリと変わります。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment