{"id":587,"date":"2014-07-04T16:51:01","date_gmt":"2014-07-04T08:51:01","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=587"},"modified":"2016-07-15T15:48:50","modified_gmt":"2016-07-15T07:48:50","slug":"uiviewcontroller%e5%90%84%e4%b8%aa%e6%96%b9%e6%b3%95%e7%9a%84%e5%8a%a0%e8%bd%bd%e9%a1%ba%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/project\/2014\/07\/04\/165101587.html","title":{"rendered":"UIViewController\u5404\u4e2a\u65b9\u6cd5\u7684\u52a0\u8f7d\u987a\u5e8f"},"content":{"rendered":"<p>\u52a0\u8f7d\u8fc7\u7a0b:<\/p>\n<p>\u4e00\u822c\u60c5\u51b5\u4e0b\u8c03\u7528 init\u65b9\u6cd5\u6216\u8005\u8c03\u7528initWithNibName\u65b9\u6cd5\u5b9e\u4f8b\u5316UIViewController, \u4e0d\u7ba1\u8c03\u7528\u54ea\u4e2a\u65b9\u6cd5\u90fd\u4e3a\u8c03\u7528initWithNibName(\u65b9\u6cd5\u5b9a\u4e49\u5982\u4e0b)<\/p>\n<p><strong>&#8211; (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil<\/strong><\/p>\n<p>\u63a5\u7740\u4f1a\u8c03\u7528loadView\u65b9\u6cd5\u6765\u751f\u6210UIViewController.view<\/p>\n<p><strong>&#8211; (void)loadView<\/strong><\/p>\n<p>\u7136\u540e\u8c03\u7528 viewDidLoad\u65b9\u6cd5<\/p>\n<p><strong>&#8211; (void)viewDidLoad<\/strong><\/p>\n<p>\u5982\u679cloadView\u4e0d\u80fd\u751f\u6210UIViewController.view\u7cfb\u7edf\u5c06\u4f1a\u53cd\u590d\u8c03\u7528loadView\u53caviewDidLoad\u65b9\u6cd5, \u5e76\u4e14\u6700\u7ec8\u8c03\u7528[super loadView] \u65b9\u6cd5\u8fd4\u56deUIViewController.view<\/p>\n<p>\u7136\u540e\u4f9d\u6b21\u8c03\u7528\u5982\u4e0b2\u4e2a\u65b9\u6cd5, \u8fd92\u4e2a\u65b9\u6cd5\u4e5f\u5341\u5206\u91cd\u8981, \u5728UINavigationController\u7684POP\u64cd\u4f5c\u540e\u6709\u65f6\u5c06\u8981\u663e\u793a\u7684UIViewController\u4e2d\u7684View\u5e76\u6ca1\u6709\u91ca\u653e(\u4e5f\u6709\u53ef\u80fd\u91ca\u653e\u6389) , UIViewController\u5c06\u4e0d\u4f1a\u8c03\u7528\u4e0a\u9762\u7684\u4e09\u4e2a\u65b9\u6cd5(initWithNibName,loadView,viewDidLoad) \u800c\u4f1a\u8c03\u7528\u4e0b\u9762\u8fd92\u4e2a\u65b9\u6cd5<\/p>\n<p><strong>&#8211; (void)viewWillAppear:(BOOL)animated;<\/p>\n<p>&#8211; (void)viewDidAppear:(BOOL)animated;<\/strong><\/p>\n<p>\u5728iOS5.0\u4e2d\u8fd8\u6dfb\u52a0\u4e862\u4e2a\u51fd\u6570:<\/p>\n<p><strong><em>&#8211; (void)viewWillLayoutSubviews ;<\/p>\n<p>&#8211; (void)viewDidLayoutSubviews;<\/em><\/strong><\/p>\n<p>\u53e6\u5916\u5982\u679c\u4f60\u8fd9\u6837\u5199:<!--more--><\/p>\n<pre lang=\"objc\" line=\"1\">- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{\n\nself = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];\n\nif (self) {\n\nUIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];\n\nself.view = view;\n\n[view release];\n\n\/\/ Custom initialization\n\nNSLog(@\u201dinitWithNibName\u201d);\n\n}\n\nreturn self;\n\n}<\/pre>\n<p>\u90a3\u4e48loadView\u548cviewDidLoad \u65b9\u6cd5\u5c06\u4e0d\u4f1a\u88ab\u8c03\u7528<\/p>\n<p>\u5378\u8f7d\u8fc7\u7a0b<\/p>\n<p><strong>&#8211; (void)viewWillDisappear:(BOOL)animated;<\/p>\n<p>&#8211; (void)viewDidDisappear:(BOOL)animated;<\/p>\n<p><em>&#8211; (void)viewWillUnload;<\/em>\/\/iOS5.0\u6dfb\u52a0<\/p>\n<p>&#8211; (void)viewDidUnload;<\/p>\n<p>&#8211; (void)dealloc;<\/strong><\/p>\n<p>PS: \u5f53\u7a0b\u5e8f\u6536\u5230\u5185\u5b58\u4e0d\u8db3\u7684\u8b66\u544a\u540e, \u7a0b\u5e8f\u5185\u5b58\u4e2d\u7684\u6240\u6709\u7684UIViewController\u90fd\u5c06\u4f1a\u6536\u5230didReceiveMemoryWarning\u8c03\u7528\u6d88\u606f. \u76ee\u7684\u662f\u5c06\u5f53\u524d\u4e0d\u663e\u793a\u7684UIViewController\u4e2d\u7684view\u91ca\u653e\u6389(\u4e0d\u4f1a\u8c03\u7528UIViewController\u7684dealloc\u65b9\u6cd5), \u6240\u4ee5\u5f53\u8be5UIViewController\u518d\u6b21\u663e\u793a\u7684\u65f6\u5019\u53c8\u8981\u751f\u6210\u4e00\u6b21, \u6b64\u65f6\u5b83\u4f1a\u8c03\u7528loadView-> viewDidLoad ->viewWillAppear\u7b49, \u8fd9\u65f6\u6700\u5bb9\u6613\u9020\u6210\u5185\u5b58\u6cc4\u6f0f!<\/p>\n<p><strong>&#8211; (void)didReceiveMemoryWarning;<\/p>\n<p><em>&#8211; (void)viewWillUnload;<\/em>\/\/iOS5.0\u6dfb\u52a0<\/p>\n<p>&#8211; (void)viewDidUnload;<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u52a0\u8f7d\u8fc7\u7a0b: \u4e00\u822c\u60c5\u51b5\u4e0b\u8c03\u7528 init\u65b9\u6cd5\u6216\u8005\u8c03\u7528initWithNibName\u65b9\u6cd5\u5b9e\u4f8b\u5316UIViewController, \u4e0d\u7ba1\u8c03\u7528\u54ea\u4e2a\u65b9\u6cd5\u90fd\u4e3a\u8c03\u7528initWithNibName(\u65b9\u6cd5\u5b9a\u4e49\u5982\u4e0b) &#8211; (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil \u63a5\u7740\u4f1a\u8c03\u7528loadView\u65b9\u6cd5\u6765\u751f\u6210UIViewController.view &#8211; (void)loadView \u7136\u540e\u8c03\u7528 viewDidLoad\u65b9\u6cd5 &#8211; (void)viewDidLoad \u5982\u679cloadView\u4e0d\u80fd\u751f\u6210UIViewController.view\u7cfb\u7edf\u5c06\u4f1a\u53cd\u590d\u8c03\u7528loadView\u53caviewDidLoad\u65b9\u6cd5, \u5e76\u4e14\u6700\u7ec8\u8c03\u7528[super loadView] \u65b9\u6cd5\u8fd4\u56deUIViewController.view \u7136\u540e\u4f9d\u6b21\u8c03\u7528\u5982\u4e0b2\u4e2a\u65b9\u6cd5, \u8fd92\u4e2a\u65b9\u6cd5\u4e5f\u5341\u5206\u91cd\u8981, \u5728UINavigationController\u7684POP\u64cd\u4f5c\u540e\u6709\u65f6\u5c06\u8981\u663e\u793a\u7684UIViewController\u4e2d\u7684View\u5e76\u6ca1\u6709\u91ca\u653e(\u4e5f\u6709\u53ef\u80fd\u91ca\u653e\u6389) , UIViewController\u5c06\u4e0d\u4f1a\u8c03\u7528\u4e0a\u9762\u7684\u4e09\u4e2a\u65b9\u6cd5(initWithNibName,loadView,viewDidLoad) \u800c\u4f1a\u8c03\u7528\u4e0b\u9762\u8fd92\u4e2a\u65b9\u6cd5 &#8211; (void)viewWillAppear:(BOOL)animated; &#8211; (void)viewDidAppear:(BOOL)animated; \u5728iOS5.0\u4e2d\u8fd8\u6dfb\u52a0\u4e862\u4e2a\u51fd\u6570: &#8211; (void)viewWillLayoutSubviews ; &#8211; (void)viewDidLayoutSubviews; \u53e6\u5916\u5982\u679c\u4f60\u8fd9\u6837\u5199:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[20],"class_list":["post-587","post","type-post","status-publish","format-standard","hentry","category-project","tag-basics"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/587","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=587"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/587\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}