Ответ 1
В версиях iOS до 11 добавление [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
работало чудесно, чтобы включить интерактивный отбор выбора ячейки. Спасибо @Dima за это!
Как и в iOS 11, из-за изменений с интерактивными переходами это больше не работает. Чтобы включить интерактивный отбор на iOS 11+, вы можете использовать UITableViewController
, потому что он реализует его для вас, иначе вы можете реализовать его, оживив отмена выбора вместе с координатором перехода, например:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
if (selectedIndexPath != nil) {
if (self.transitionCoordinator != nil) {
[self.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[self.tableView deselectRowAtIndexPath:selectedIndexPath animated:YES];
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
if (context.cancelled) {
[self.tableView selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}
}];
} else {
[self.tableView deselectRowAtIndexPath:selectedIndexPath animated:animated];
}
}
}
И в Swift:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let selectedIndexPath = tableView.indexPathForSelectedRow {
if let coordinator = transitionCoordinator {
coordinator.animate(alongsideTransition: { context in
self.tableView.deselectRow(at: selectedIndexPath, animated: true)
}) { context in
if context.isCancelled {
self.tableView.selectRow(at: selectedIndexPath, animated: false, scrollPosition: .none)
}
}
} else {
self.tableView.deselectRow(at: selectedIndexPath, animated: animated)
}
}
}