Cancel the problem of cell selection when tableView returns

When operating on the table UITableView, sometimes when the user selects the table row, it is necessary to automatically cancel the selection. To achieve this effect, the principle is that when a table row is selected, the didSelectRowAtIndexPath method will be called. As long as in this method, performSelector is called to execute the method of unselecting the table row. The sample code is as follows:

 

- ( void ) unselectCurrentRow
{
   // Animate the deselection
   [self.tableView deselectRowAtIndexPath: [self.tableView indexPathForSelectedRow] animated:YES];
}
  
- ( void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath
{
   // Any other table management you need
   ...
  
   // After one second, unselect the current row
   [self performSelector:@selector(unselectCurrentRow) withObject:nil afterDelay:1.0];
} 
The delay time can also be set in performSelector. In the unselectCurrentRow method, the selection of the table row is canceled, and the animation effect is realized. 
 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326262078&siteId=291194637