2012年3月17日土曜日

UITableCellのswipe時のボタン表示


UITableViewのdelegate(通常はUITableViewController)に次のデリゲートメソッドを実装します。

//swipeでボタンを表示させるCellの場合にYESを返す。
- (BOOL)tableView:(UITableView *)tableView
       canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (someCondition == YES) {
        return YES;
    } else {
        return NO;
    }
}

//swipeされたときのボタンの名前
- (NSString *)tableView:(UITableView *)tableVie
       titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"ボタン名";
}

//swipeで表示されたボタンタップ時に呼ばれる。
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
     //someAction
}

0 件のコメント: