viewDidAppear 之后的代码执行?

Code execution after viewDidAppear?

OK, I'm running into a strange issue which leads me to ask the question - does any code run after viewDidAppear?

这里有更多信息。我有一个带有自定义单元格的 tableViewController (TVC)。其中一个单元有一个按钮作为附件。加载此 TVC 时,将设置按钮的 backgroundColor。使用按钮选择单元格会显示一个带有颜色选择器 (CPVC) 的视图控制器。当 CPVC 被关闭时,它首先运行一个 onDismissal 块(在 TVC 中设置)以调整 TVC 中按钮的颜色。到目前为止,代码运行良好,并且在关闭颜色选择器视图控制器时设置了按钮的颜色。

我发现的问题是在设置按钮的颜色后,由于某种原因它会在大约 0.25 秒后重置为之前的颜色。您可以看到在颜色选择器集中选择的颜色,然后按钮的颜色过渡到它之前的颜色。我不明白为什么会这样。当我在调试器中检查局部颜色变量时,所有这些变量都更新为新颜色,并且不确定对先前颜色的引用在哪里仍然存在。我已将 NSLog 语句插入到 TVC 的 viewDidAppear 方法中,并已验证在关闭颜色选择器后,按钮的颜色设置为用户在 [=12= 结束时选择的任何颜色] 方法。只有在之后颜色才会改变。 viewDidAppear之后的运行是什么?

用户 rmady 指引了我正确的方向。从来不知道 UITableViewControllers 在 vi​​ewWillDisappear 上重置了 tableView。根据文档:

When the table view is about to appear the first time it’s loaded, the table-view controller reloads the table view’s data. It also clears its selection (with or without animation, depending on the request) every time the table view is displayed. The UITableViewController class implements this in the superclass method viewWillAppear:. You can disable this behavior by changing the value in the clearsSelectionOnViewWillAppear property.

所以我所要做的就是将 clearsSelectionOnViewWillAppear 设置为 NO,然后一切正常。谢谢rmady