Scrolling to remove options in UITableView issues

I want to use the “swipe to delete” option in my project.

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { NSDictionary *userData = [_contactsArray objectAtIndex:indexPath.row]; NSLog(@"delete row %@",userData); } } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } 

I use this code, but it gives the following result, which I do not want. enter image description here

I do not want the left side minus the sign on the cell. I just want to make napkins and show the delete button. The same code that I used in my previous project, and it works fine (i.e. just swipe the screen to show the delete button, without a minus sign on the left)

Please help me solve this problem.

+6
source share
4 answers

You are overriding the correct delegation methods for the delete functionality. As for the minus signs:

Hide the minus sign as follows:

 self.yourTableView.editing = NO; //or simply remove this line of code altogether because this property is NO by default 

Show minus sign as follows:

 self.yourTableView.editing = YES; 
+9
source

First create a table view and set the delegation method and data source for it.

  self.contacts=[[UITable alloc]init]; self.contacts.dataSource=self; self.contacts.delegate=self; self.contacts.userInteractionEnabled=YES; //self.contacts.editing = YES; [self.view addSubview:self.contacts]; 

And then override the delegation methods and data sources, override the following methods to delete.

 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return YES if you want the specified item to be editable. return YES; } // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { //add code here for when you hit delete } } 

For the minus sign on the left, use self.contacts.editing = YES; In my case, I do not want this minus sign to simply not use this property or set self.contacts.editing = NO;

Thanks, hw731 , to remind me of this property, I spent half a day on it.

+3
source

Try the following:

  - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return YES if you want the specified item to be editable. return YES; } // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { //add code here for when you hit delete } } 
+1
source

It looks like you are turning the tableView.editing flag tableView.editing that the rows are displayed with a minus sign. try finding self.tableView.editing = YES; and do it NO or just comment out this line.

0
source

Source: https://habr.com/ru/post/951641/


All Articles