UITableView Edit mode

后端 未结 5 987
逝去的感伤
逝去的感伤 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:43

    To load a tableView in edit mode you should call setEditing(true, animated: false) in viewDidLoad().

    If your view controller is a subclass of UITableViewController there's no need to change, just make the above call. Otherwise if your view controller is a subclass of UIViewController, then you should make a call in this way: tableView.setEditing(true, animated: true).

    Tested with Swift 2.2.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-24 05:53

    [self.tableView setEditing:!self.tableView.isEditing animated:YES];

    0 讨论(0)
  • 2020-12-24 05:54

    try this...

    [tableView setEditing: YES animated: YES];
    
    0 讨论(0)
  • 2020-12-24 06:07

    as Anish pointed to using

    [tableView setEditing: YES animated: YES]; 
    

    But you need to have it in viewWillAppear view event to make it work.

    0 讨论(0)
提交回复
热议问题