UITableView Edit mode

后端 未结 5 988
逝去的感伤
逝去的感伤 2020-12-24 05:13

I have UITableView and I am trying to load it by default in edit mode. The problem is when I this line table.editing=TRUE; my rows disappear, I im

5条回答
  •  独厮守ぢ
    2020-12-24 05:46

    In ViewDidLoad write

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style: UIBarButtonItemStyleBordered target:self action:@selector(addORDoneRows)];
    [self.navigationItem setLeftBarButtonItem:addButton];
    

    addORDoneRow

    - (void)addORDoneRows
    {
        if(self.editing)
        {
            [super setEditing:NO animated:NO];
            [_dbSongsTblView setEditing:NO animated:NO];
            [_dbSongsTblView reloadData];
            [self.navigationItem.leftBarButtonItem setTitle:@"Edit"];
            [self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStylePlain];
        }
        else
        {
            [super setEditing:YES animated:YES];
            [_dbSongsTblView setEditing:YES animated:YES];
            [_dbSongsTblView reloadData];
            [self.navigationItem.leftBarButtonItem setTitle:@"Done"];
            [self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStyleDone];
        }
    }
    

    For MultipleSelection of Row

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

    Note: There are Three Editiing Style as below

    UITableViewCellEditingStyleNone,
    UITableViewCellEditingStyleDelete,
    UITableViewCellEditingStyleInsert
    

    Note: And for multiple Selection set Selection and Editing Style to Multiple from Attribute inspector

提交回复
热议问题