Swipe To Delete TableView Row

后端 未结 8 1002
暖寄归人
暖寄归人 2020-12-24 06:10

I have my array:

self.colorNames = [[NSArray alloc] 
initWithObjects:@\"Red\", @\"Green\",
@\"Blue\", @\"Indigo\", @\"Violet\", nil];

I\'ve

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-24 06:56

    You have to add UITableViewDelegate and UITableViewDataSource methods.

    You can add multiple buttons on UITableView Row Swipe:

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
            return YES;
        }
    
    -(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
        
            UITableViewRowAction *delete = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
            {
                // Delete something here
            }];
            delete.backgroundColor = [UIColor redColor];
        
            UITableViewRowAction *more = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@" More " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
            {
               //You function call:
            }];
            more.backgroundColor = [UIColor colorWithRed:0.188 green:0.514 blue:0.984 alpha:1];
        
            return @[delete, more]; //array with all the buttons.
        }`
    

提交回复
热议问题