用于 UIView 的 iOS viewDidLoad [英] iOS viewDidLoad for UIView

查看:17
本文介绍了用于 UIView 的 iOS viewDidLoad的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 ViewController 中,有 ViewDidLoad 可以知道 VC 何时加载.

In a ViewController, there is ViewDidLoad to know when the VC has loaded.

对于 UIView,当视图加载时我必须使用什么方法?

For a UIView, what method do i have to use when the view loaded?

这个方法会被任何 init 调用吗?

Would this method be called with any init?

没有 XIB,只是以编程方式.

edit: No XIB, just programmatically.

推荐答案

如果你从 XIB 文件加载它,awakeFromNib 方法将在加载完成后被调用:

If you load it from a XIB file, the awakeFromNib method will be called once loading finishes:

override public func awakeFromNib() {
    super.awakeFromNib();

    // ... loading logic here ...
}

更新;在没有 XIB 的情况下,您可能必须使用 观察与视图相关的更改 区域中的一种方法来推断它文档(例如,didMoveToSuperview).但是,如果可能,更好的方法是从视图控制器的 viewDidLoad 方法向您的视图发送消息.

Update; In the case of no XIB, you will probably have to infer it using one of the methods from the Observing View-Related Changes area of the docs (for example, didMoveToSuperview). However, a better way is to send a message to your views from the view controller's viewDidLoad method if possible.

这篇关于用于 UIView 的 iOS viewDidLoad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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