有没有好的方法来检查 UIViewController 是否出现?
我在 UIViewController 中有一个方法可以根据它当前是否出现来执行操作。 当 viewDidAppear/viewDidDisappear 被调用时,我可以放置一个 BOOL 标志来切换 YES/NO,但是是否有更好的方法/方法来检查?
谢谢。
I have a method in a UIViewController to do things base on if it is currently appearing.
I can put a BOOL flag to switch YES/NO when the viewDidAppear/viewDidDisappear is called but is there a better way/method to check?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
viewDidAppear
方法是您最好的选择。不过,我见过一些边缘情况,根据各种因素,不调用viewDidAppear
/viewDidDisappear
。仅仅因为我喜欢控制并且不喜欢任何未知因素,我通常会在控制器中公开一个方法,该方法在调用时完成所有设置,并且当我知道我的控制器正在被调用时,我会调用此方法。
一个粗略示例:
然后...
The
viewDidAppear
method is your best bet. I have seen some edge cases, though, whereviewDidAppear
/viewDidDisappear
are not called depending on various factors.Just because I enjoy the control and don't like any unknowns, I typically expose a method in my controllers that do all the setup when called and I would call this method when I know that my controller is getting called into action.
A rough example:
Then...