UITableViewCell doesn't get deselected when swiping back quickly

后端 未结 16 1713
甜味超标
甜味超标 2021-01-29 23:49

I\'ve now updated three of my apps to iOS 7, but in all three, despite them not sharing any code, I have the problem where if the user swipes to go back in the navigation contro

16条回答
  •  情书的邮戳
    2021-01-30 00:46

    Based on Rhult's code, I made a few changes.

    This implementation allow user to cancel swipe back and still keep selected for future swipe back deselect animation

    @property(strong, nonatomic) NSIndexPath *savedSelectedIndexPath;
    
    
    - (void)viewDidLoad {
       [super viewDidLoad];
       self.clearsSelectionOnViewWillAppear = NO;
    }
    
    -(void) viewDidAppear:(BOOL)animated {
       [super viewDidAppear:animated];
       self.savedSelectedIndexPath = nil;
    }
    
    -(void) viewWillDisappear:(BOOL)animated {
       [super viewWillDisappear:animated];
       if (self.savedSelectedIndexPath && ![self.tableView indexPathForSelectedRow]) {
           [self.tableView selectRowAtIndexPath:self.savedSelectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
       } else {
          self.savedSelectedIndexPath = [self.tableView indexPathForSelectedRow];
       }
    }
    

提交回复
热议问题