我有一个带有故事板中单元格的UITableView,以及一个将单元格连接到另一个视图的段。
当您选择一个单元格时,它会显示单元格选择动画(在我的示例中,单元格变为灰色),并将另一个视图推送到屏幕上。但当您返回到表视图时,取消选择动画根本不会显示(与选择动画相反)。因为我只是使用了一个segue,所以我希望这在默认情况下会得到处理。
有没有办法强制它显示取消选择动画?
发布于 2011-12-28 08:30:33
我不确定segues的用法,但我经常想在视图控制器出现时刷新数据。但是,如果重新装入该表,则会清除select行。下面是一些代码,我用它来维护选中的行,并在返回时显示取消选择的动画。这可能会对你有所帮助,所以我会把它贴在这里。
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSIndexPath *indexPath = [tableView indexPathForSelectedRow];
[tableView reloadData];
if(indexPath) {
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSIndexPath *indexPath = [tableView indexPathForSelectedRow];
if(indexPath) {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
发布于 2011-12-16 07:52:06
如果视图控制器是UITableViewController
的子类,并且clearsSelectedOnViewWillAppear
设置为YES
(默认值),则会自动处理此问题。
在您的例子中,您可以使用与UITableViewController
完全相同的方式来完成此操作。取消选择-viewWillAppear:
中的选定行。
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
[self.tableView deselectRowAtIndexPath:selectedIndexPath animated:YES];
}
发布于 2011-12-27 04:00:13
确保调用的是viewWill...
和viewDid...
方法的super
实现
https://stackoverflow.com/questions/8531255
复制相似问题