When editing, `UITableView` does not call didSelectRowAtIndexPath ??

前端 未结 4 706
遥遥无期
遥遥无期 2020-12-29 18:11

I have a UITableViewController where the user should be able to edit the items. In order to enable editing I use this :

self.navigationItem.righ         


        
相关标签:
4条回答
  • 2020-12-29 18:37

    You gotta set the allowsSelectionDuringEditing property of UITableView to true.

    Reference: UITableView - allowsSelectionDuringEditing

    0 讨论(0)
  • 2020-12-29 18:39

    Do you set the self.editing = YES when the edit button is tapped?

    When in editing mode this method is called, instead of didSelectRow when you tap a row:

    tableView:commitEditingStyle:forRowAtIndexPath:.
    
    0 讨论(0)
  • 2020-12-29 18:45

    I solved this problem other way. My Edit button was on my own Navigation bar and that was the reason it wasn't called. After I've embedded VC inside Navigation Controller, and put new Edit button inside its Navigation Item, Edit button started to get called.

    0 讨论(0)
  • 2020-12-29 18:52

    but as soon as I hit the edit button and while editing is active, this method does not seemed to be called.

    Any idea what I missing ?

    Yes. You are expecting tableView:didSelectRowAtIndexPath: to be called when a button in your nav bar is tapped. This will never happen. That method is only called when a row is selected.

    When the edit button is tapped, you will want to put your table into editing mode. In your view controller:

    - (void)setEditing:(BOOL)editing animated:(BOOL)animated
    {
        [super setEditing:editing animated:animated]; // must be called first according to Apple docs
    
        [self.tableView setEditing:editing animated:animated];
    }
    

    Then you handle editing events by adding a tableView:commitEditingStyle:forRowAtIndexPath: method.

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