将UINavigationController弹出到UITableView并显示不同的选定行

时间:2011-09-08 06:25:30

标签: ios uitableview uinavigationcontroller pushviewcontroller popviewcontroller

我正在创建一个应用程序,UITableView是其所在UINavigationController堆栈中的第一个项目。在UITableView上进行选择会将视图推送到“ DetailedViewController”。在DetailedViewController中,您可以浏览填充表格视图的项目。

当弹出DetailedViewController并返回UITableView时,如何取消选择我通过DetailedViewController导航到的相应项目,并将其显示在UITableView的中心位置{1}}?

每个人都可以看到的一个例子是Mail应用程序。当您进入收件箱并进行选择时,请按“DetailedViewController”。在那里,您可以浏览UITableView中填充的项目。当您弹出DetailedViewController时,它会取消选择DetailedViewController中您最后查看的相应项目。

2 个答案:

答案 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];
     ...
}