当从UINavigationController子屏幕返回时,如何保持UITableView所选行? [英] How do I maintain the UITableView selected row when returning from a UINavigationController child screen?

查看:71
本文介绍了当从UINavigationController子屏幕返回时,如何保持UITableView所选行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableView的客户,其中选择行/客户。然后,用户可以在UINavigationController堆栈上推送另一个视图以添加新客户。当我弹出子屏幕并返回到UITableView时,先前选择的行不再被选中。

I have a UITableView of customers where a row/customer is selected. The user can then push another view on the UINavigationController stack to add a new customer. When I pop the child screen and return to the UITableView the previously selected row is no longer selected.

我可以重新选择viewDidAppear()中的行,但看起来很糟糕,你可以看到取消选择和选择。

I can re-select the row in viewDidAppear() but it looks bad as you can see the deselect and the select. Is there a way to maintain the selected row when returning from the child screen?

推荐答案

我假设你使用的是表视图控制器,否则你的责任是写这个行为反正。在表视图控制器,虽然,很容易。只需添加viewDidLoad:

I assume you are using a table view controller, as otherwise it is your responsibility to write this behaviour anyway. In a table view controller, though, it's easy. Just add in viewDidLoad:

self.clearsSelectionOnViewWillAppear = NO;

这将保持行被选中,除非您手动取消选择行或用户选择表。

That will keep the row selected, unless you manually deselect the row or the user selects another row on the table.

这篇关于当从UINavigationController子屏幕返回时,如何保持UITableView所选行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆