UIView - 如何在加载视图时收到通知? [英] UIView - How to get notified when the view is loaded?

查看:99
本文介绍了UIView - 如何在加载视图时收到通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 UIView viewDidLoad UIViewController C $ C> ???
我需要在 UIView 加载(子类 UIView )后立即通知我,并执行一些行动。

Is there anything similar to the viewDidLoad of UIViewController for a UIView??? I need to be notified as soon as a UIView has loaded (Subclass of UIView), and perform some actions.

推荐答案

根据您需要执行的操作类型,有以下几种方法:

Depending on what kind of actions you need to perform, there are several techniques:


  1. - (id)initWithFrame:(CGRect)frame - UIView指定的
    初始值设定项;总是发送到UIView来初始化它,除非从笔尖加载
    视图;

  2. - (id)initWithCoder:(NSCoder *)编码器 - 每当从笔尖加载视图时,总是发送初始化UIView;

  3. - (void)awakeFromNib - 在nib中的所有对象初始化并连接后发送;仅在从笔尖加载对象时适用;你必须打电话给super;

  4. - (void)willMoveToSuperview:(UIView *)newSuperview - 在视图添加为之前立即发送子视图到另一个视图;从超级视图中删除视图时, newSuperview 可能为零;

  5. - (void)willMoveToWindow :( UIWindow *)newWindow - 在视图(或其超级视图)添加到窗口之前立即发送;从窗口中删除视图时, newWindow 可能为nil;

  6. - (void)didMoveToSuperview - 在视图插入视图层次结构后立即发送;

  7. - (void)didMoveToWindow - 立即发送在视图获取其窗口属性后设置。 -

  1. -(id)initWithFrame:(CGRect)frame - UIView's designated initializer; always sent to a UIView to initialize it, unless the view is loaded from a nib;
  2. -(id)initWithCoder:(NSCoder *)coder - always sent to initialize a UIView whenever the view is loaded from a nib;
  3. -(void)awakeFromNib - sent after all the objects in the nib are initialized and connected; applicable only if you load the object from a nib; you must call super;
  4. -(void)willMoveToSuperview:(UIView *)newSuperview - sent immediately before the view is added as a subview to another view; newSuperview may be nil when you remove the view from its superview;
  5. -(void)willMoveToWindow:(UIWindow *)newWindow - sent immediately before the view (or its superview) is added to a window; newWindow may be nil when you remove the view from a window;
  6. -(void)didMoveToSuperview - sent immediately after the view is inserted into a view hierarchy;
  7. -(void)didMoveToWindow - sent immediately after the view gets its window property set. -

基本上,您可以选择在初始化期间执行操作(1& 2),从笔尖加载后(3) ,在插入视图层次结构(4& 5)之前和之后(6& 7)。

Basically, you can choose to perform your actions during initialization (1 & 2), after loading from a nib (3), before insertion into a view hierarchy (4 & 5) and after that (6 & 7).

这篇关于UIView - 如何在加载视图时收到通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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