Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discard segue during uitableview editing mode

When I change my uitableview to edit mode, i'd like the user to be able to select a cell without the segue taking place. The segue was linked in the storyboard. Is there a way to disable the segue during edit mode?

I can't disable interaction with the cell during edit more because I need to pick up on the editing control (insert button) press.

like image 716
Jonathan Avatar asked Feb 04 '13 01:02

Jonathan


2 Answers

In your view controller, override:

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender{
    return !self.isEditing;
}

Inside that method check if this is the correct segue, and verify the edit state. If the editing is on, return NO; otherwise, return YES.

like image 91
Sergey Kalinichenko Avatar answered Oct 21 '22 02:10

Sergey Kalinichenko


Swift 3+:

Assuming you've inherited from UITableViewController:

override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
    return !tableView.isEditing
}

Note this will disable all segues while editing. If you have more than one and you want some to remain enabled in edit mode, apply the appropriate logic within this function to return true or false as appropriate.

like image 21
biomiker Avatar answered Oct 21 '22 02:10

biomiker