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

问题描述

UIView viewDidLoad 是什么?

我有一个带有xib的 UIView 。我想在加载时隐藏其中一个子视图。
我试图使用它。

I have a UIView with xib. I would like to hide one of it's subviews when it is loaded.I tried to use this.

- (id)initWithCoder:(NSCoder *)aDecoder{
    ....
    _theView.hidden = YES;
}

但子视图 _theView 此时为零。

没有帮助我,因为在创建 UIViewController 的那一刻,还没有创建 UIView 。它是以编程方式创建的,稍后会创建。

This answer didn't help me, becouse at moment of creating the UIViewController, the UIView is not created yet. It is created programaticly, later on.

推荐答案

仅当从nib文件加载视图时才会调用AwakeFromNib 。为所有视图调用
layoutSubviews ,你可以在<$ c中添加bool _loaded = yes; $ c> layoutSubviews 函数并知道视图是否已加载。

AwakeFromNib is called only if the view loaded from nib file.layoutSubviews is called for all views, you can add bool _loaded = yes; in the layoutSubviews function and know if the view loaded.

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

10-29 22:41