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

标签 ios uitableview uinavigationcontroller pushviewcontroller popviewcontroller

我正在创建一个带有 UITableView 的应用程序作为 UINavigationController 堆栈中的第一项它在里面。在 UITableView 上进行选择会将 View 推送到“DetailedViewController”。在DetailedViewController ,您可以浏览表格 View 填充的项目。

弹出 DetailedViewController 时,然后回到 UITableView , 如何取消选择我通过 DetailedViewController 导航到的相应项目并将其显示在 UITableView 的中心?

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

最佳答案

要取消选择所选行,请编写以下代码 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];

关于ios - 将 UINavigationController 弹出到 UITableView 并显示不同的选定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7343954/

相关文章:

swift - 如何在 UITabBarController 中的另一个 UINavigationController 上显示 UINavigationController?

ios - StackView 中的几个标签最初被截断但在滚动时完美显示

ios - 选择单元格时,UITableView 在滚动时改变外观?

objective-c - 错误-[NSIndexPath 发布] : message sent to deallocated instance 0x6a9d790

javascript - forge.facebook.ui 回调在 iOS 上用 null 调用

ios - 运行多个 HealthKit 示例查询的更好方法?

objective-c - 为圆圈上的刻度制作动画以保持中心位置

快速 UINavigationController 委托(delegate)

ios - 弹出 Objective -C 时如何保留 ViewController

iphone - 如何在 iPhone 应用程序的 UINavigationBar 中添加图像