iOS LifeCycle

Method Class/Protocal Description
+ (void)load NSObject 1、Invoked whenever a class or category is added to the Objective-C runtime(class和category添加到runtime时调用)
2、A class’s +load method is called after all of its superclasses’ +load methods(class在superclass后调用)
3、A category +load method is called after the class’s own +load method(category在class后调用)
+ (void)initialize NSObject 1、Initializes the class before it receives its first message.(在收到第一条消息之前初始化类)
2、 Superclasses receive this message before their subclasses.(superclass先调用)
3、The runtime sends the initialize message to classes in a thread-safe manner.(线程安全)
- (instancetype)init NSObject 1、In a custom implementation of this method, you must invoke super’s Initialization then initialize and return the new object.(必须调用super的init)
- (instancetype)initWithFrame:(CGRect)frame UIView 1、The origin of the frame is relative to the superview in which you plan to add it. (原点相对于父视图)
2、If you create a view object programmatically, this method is the designated initializer for the UIView class.(以编程方式创建视图对象,则此方法是UIView类的指派初始化方法)
3、 Subclasses can override this method to perform any custom initialization but must call super at the beginning of their implementation.(子类必须调用super)
4、If you use Interface Builder to design your interface, this method is not called when your view objects are subsequently loaded from the nib file.(使用Interface Builder创建,从nib文件加载视图对象时不会调用此方法)
- (instancetype)initWithCoder:(NSCoder *)aDecoder NSCoding 1、Objects in a nib file are reconstituted and then initialized using their initWithCoder: method, which modifies the attributes of the view to match the attributes stored in the nib file. (nib文件中的对象使用initWithCoder: 完成初始化和属性修改)
- (void)awakeFromNib NSObject 1、The nib-loading infrastructure sends an awakeFromNib message to each object recreated from a nib archive, but only after all the objects in the archive have been loaded and initialized.(nib文件中的所有对象被加载和初始化后收到该消息)
2、When an object receives an awakeFromNib message, it is guaranteed to have all its outlet and action connections already established.(收到消息时,所有的IBOutlet和IBAction已经连接完毕)
3、You must call the super implementation of awakeFromNib to give parent classes the opportunity to perform any additional initialization they require.(需要调用super)
4、Objects that conform to the NSCoding protocol (including all subclasses of UIViewand UIViewController) are initialized using their initWithCoder:method.(符合NSCoding协议的对象使用initWithCoder:初始化)
- (void)loadView UIViewController 1、You should never call this method directly. The view controller calls this method when its view property is requested but is currently nil. This method loads or creates a view and assigns it to the view property.(不要直接调用,ViewController访问view属性但其为nil时调用)
2、If you use Interface Builder to create your views and initialize the view controller, you must not override this method.(如果使用IB,不应该覆写此方法)
3、You can override this method in order to create your views manually.If you choose to do so, assign the root view of your view hierarchy to the view property.(手动创建视图时可以覆写)
4、Your custom implementation of this method should not call super.(不调用super)
5、If you want to perform any additional initialization of your views, do so in the viewDidLoad method.(其他初始化操作在viewDidLoad方法执行)
- (void)viewDidLoad UIViewController 1、This method is called after the view controller has loaded its view hierarchy into memory.(视图控制器加载视图结构到内存后调用)
2、This method is called regardless of whether the view hierarchy was loaded from a nib file or created programmatically in the loadView method.(无论IB还是编码方式都会调用)
- (void)viewWillAppear:(BOOL)animated UIViewController 1、This method is called before the view controller'��s view is about to be added to a view hierarchy and before any animations are configured for showing the view.(添加到视图层次之前调用)
2、If you override this method, you must call super at some point in your implementation.(必须调用super)
3、If a view controller is presented by a view controller inside of a popover, this method is not invoked on the presenting view controller after the presented controller is dismissed.
- (void)viewDidAppear:(BOOL)animated UIViewController 1、If you override this method, you must call super at some point in your implementation.
2、If a view controller is presented by a view controller inside of a popover, this method is not invoked on the presenting view controller after the presented controller is dismissed.
- (void) viewWillLayoutSubviews UIViewController 1、Called just before the view controller's view's layoutSubviews method is invoked.
- (void) viewDidLayoutSubviews UIViewController 1、Called just after the view controller's view's layoutSubviews method is invoked.
- (void)willMoveToParentViewController:(UIViewController *)parent UIViewController 1、Called just before the view controller is added or removed from a container view controller.
- (void)didMoveToParentViewController:(UIViewController *)parent UIViewController 1、Called after the view controller is added or removed from a container view controller.
- (void)drawRect:(CGRect)rect UIView 1、 You do not need to override this method if your view sets its content in other ways.(如果视图仅是设置其内容无需覆盖此方法)
2、If you subclass UIView directly, your implementation of this method does not need to call super.However, if you are subclassing a different view class, you should call super at some point in your implementation.(如果直接子类化UIView,方法的实现不需要调用super。但如果要子类化其他视图类,则应在实现中的某个时刻调用super)
3、This method is called when a view is first displayed or when an event occurs that invalidates a visible part of the view. (首次显示视图或发生使视图的可见部分无效的事件时,将调用此方法)
4、You should never call this method directly yourself. (不应该直接调用这个方法)
- (void)layoutSubviews UIView 1、The default implementation of this method does nothing on iOS 5.1 and earlier. Otherwise, the default implementation uses any constraints you have set to determine the size and position of any subviews.(iOS5.1及更早版本默认实现不起作用,之后版本用来确定子视图位置大小)
2、Subclasses can override this method as needed to perform more precise layout of their subviews. (子类可以重写方法,进行更精确的布局)
3、You should not call this method directly.
4、If you want to force a layout update, call the setNeedsLayout method instead to do so prior to the next drawing update. (如果要强制布局更新,请在下次图形更新之前调用setNeedsLayout方法)
5、If you want to update the layout of your views immediately, call the layoutIfNeeded method. (如果要立即更新视图的布局,请调用layoutifneeded方法)
- (void)setNeedsLayout UIView 1、Invalidates the current layout of the receiver and triggers a layout update during the next update cycle.(设置当前布局无效并在下一个更新周期触发布局更新)
2、Call this method on your application’s main thread when you want to adjust the layout of a view’s subviews.(在主线程调用)
3、This method makes a note of the request and returns immediately. Because this method does not force an immediate update, but instead waits for the next update cycle, you can use it to invalidate the layout of multiple views before any of those views are updated. (此方法记录并立即返回,不强制立即更新而是等待下一个更新周期)
4、This behavior allows you to consolidate all of your layout updates to one update cycle, which is usually better for performance. (此行为允许您将所有布局更新合并到一个更新周期,这通常对性能更好)
- (void)layoutIfNeeded UIView 1、Use this method to force the view to update its layout immediately.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 215,539评论 6 497
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,911评论 3 391
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 161,337评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,723评论 1 290
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,795评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,762评论 1 294
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,742评论 3 416
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,508评论 0 271
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,954评论 1 308
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,247评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,404评论 1 345
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,104评论 5 340
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,736评论 3 324
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,352评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,557评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,371评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,292评论 2 352

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,320评论 0 10
  • ViewsBecause view objects are the main way your applicati...
    梁光飞阅读 601评论 0 0
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,460评论 0 23
  • 以为这次旅行 能让我走出心里困境 结果并非斐然 带着沉重的心情去 旅途虽暂且放下 但回来依然沉重 该面对的逃不掉 ...
    负荷爆炸君阅读 158评论 2 1
  • 中英文对照 计算机领域,中文词汇表述含糊不清,不像英语表述的那么准确,并发和并行就是一个典型例子。 并发 conc...
    印随2018阅读 1,227评论 0 1