我正在创建一个应用程序,UITableView
是其所在UINavigationController
堆栈中的第一个项目。在UITableView
上进行选择会将视图推送到“ DetailedViewController
”。在DetailedViewController
中,您可以浏览填充表格视图的项目。
当弹出DetailedViewController
并返回UITableView
时,如何取消选择我通过DetailedViewController
导航到的相应项目,并将其显示在UITableView
的中心位置{1}}?
每个人都可以看到的一个例子是Mail应用程序。当您进入收件箱并进行选择时,请按“DetailedViewController
”。在那里,您可以浏览UITableView
中填充的项目。当您弹出DetailedViewController
时,它会取消选择DetailedViewController
中您最后查看的相应项目。
答案 0 :(得分:2)
要取消选择所选行,请编写以下代码viewDidAppear:
方法。
// Index path for selected row
NSIndexPath *selectedRow = [_tableView indexPathForSelectedRow];
// Deselet the row with animation
[_tableView deselectRowAtIndexPath:selectedRow animated:YES];
// Scroll the selected row to the center
[_tableView scrollToRowAtIndexPath:selectedRow
atScrollPosition:UITableViewScrollPositionMiddle
animated:YES];
答案 1 :(得分:0)
根据您希望动画的外观,您只需取消选择当前选定的行即可。
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
...
}