tableViewCell左划顯示多個按鈕(系統原生)


1、實現tableView的代理方法

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

2、cell添加左划按鈕

- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewRowAction *action0 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"修改" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        NSLog(@"點擊了。。%d",indexPath.row);
        
        // 收回左滑出現的按鈕(退出編輯模式)
        tableView.editing = NO;
    }];
    action0.backgroundColor = [UIColor darkGrayColor];
    
    UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"刪除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

        NSLog(@"刪除。。%d",indexPath.row);
        tableView.editing = NO;
    }];
    
    UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"刪除1" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        
        NSLog(@"刪除1。。%d",indexPath.row);
        tableView.editing = NO;
    }];
    action2.backgroundColor = [UIColor blueColor];
    return @[action1, action0,action2];
    
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM