在編輯模式中,UITableView進(jìn)行左滑操作的cell,右邊默認(rèn)會出現(xiàn)刪除按鈕.但是實際開發(fā)中可能會有需求,改變按鈕或添加一個按鈕.
只需實現(xiàn)tableView代理方法 (tableView:editActionsForRowAtIndexPath:)就可以了
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *RowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"刪除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
NSLog(@"做一些事情");
}];
RowAction.backgroundColor = [UIColor redColor];
UITableViewRowAction *RowAction1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"喜歡" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
NSLog(@"做一些事情");
}];
RowAction1.backgroundColor = [UIColor colorWithRed:220/255.0f green:220/255.0f blue:220/255.0f alpha:1.0f];
return @[RowAction,RowAction1];
}
演示效果:
演示結(jié)果