Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the swipe-delete button in one table & not another in a same view screen in Obj C?

In a iPhone application, I am using two different tableviews in same screen. Now, I want to use the swipe-delete functionality in one table view but not in the other. But when I call the delegate method 'commiteditingstyledelete' to get the swipe-delete button in both the table view. How to remove that from the other table ? I can not disable the row user-interaction as I have some textfield in tableview row. Please suggest.

like image 1000
utsabiem Avatar asked Dec 05 '25 14:12

utsabiem


1 Answers

In your delegate callback for editing cells, you have to check what table you want to use, you can set a tag to each tableView, or you're using ivars check for the instance, so:

1: with ivars

if(tableView==yourTableViewClassVar){
  //your table
}

2: with tag

set the tag 
tableView.tag=10;

...then in the callback

if(tableView.tag==10){
   //your table
}

EDIT:

The problem is , even when I swipe across Table2, the commiteditingstyle method is called and shows the delete button.

you also have to check set style of the cell in this callback:

  - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
        if (tableView.tag==10) {
            return UITableViewCellEditingStyleNone;
        }else{
            return UITableViewCellEditingStyleDelete;
        }
    }
like image 149
Mat Avatar answered Dec 07 '25 04:12

Mat