Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell reorder control, no delete button, and swipe-to-delete

I have a UITableView that I'd like to always show the reorder control, never show the little delete circle icon, and always allow for a swipe delete. Is this possible?

So far, I've only discovered two options:

  • Allowing just the swipe-to-delete (UITableViewCellEditingStyleDelete),
  • Allowing just the reorder control (setEditing:YES, UITableViewCellEditingStyleNone).

Thanks for reading

like image 540
Rogare Avatar asked Dec 27 '13 21:12

Rogare


2 Answers

To do this I combined two open source projects into:

https://github.com/adamraudonis/UITableViewCell-Swipe-for-Options

Hope that helps! Currently you can reorder by long-pressing anywhere in the TableViewCell and swipe to delete without showing the red circle.

like image 62
Adam Raudonis Avatar answered Sep 27 '22 20:09

Adam Raudonis


Apparently UITableView has a private api method to do just that:

Reorder with swipe-to-delete demo

if ([self.tableView respondsToSelector:@selector(_setAllowsReorderingWhenNotEditing:)]) {
    [self.tableView _setAllowsReorderingWhenNotEditing:YES];
} else {
    // do not ignore this branch 
}

Works in iOS 8, 9 and current betas. However, it is your responsibility to check for method availability to avoid crashes. Still would be better than using some overloaded 3rd party library (which most probably will break in future iOS releases).

like image 41
Roman B. Avatar answered Sep 27 '22 22:09

Roman B.