Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable delete but enable move cells in UITableView

I'm aware of the two methods

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return indexPath.section == 0;
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
     return YES;
}

But how can we disable delete but enable move cells in UITableView?

like image 612
lwxted Avatar asked Feb 06 '14 03:02

lwxted


2 Answers

Try adding the below delegate methods to your code.

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

- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}
like image 100
gaurish.salunke Avatar answered Oct 19 '22 00:10

gaurish.salunke


Delegate Methods for Swift 3:

func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
    return .none
}

func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
    return false
}
like image 28
Erik P. Avatar answered Oct 19 '22 01:10

Erik P.