1) ViewDidLoad- 需要的视图元素都在此方法加载,例如视图是一个Form,有3个label,这个方法一次成型(Whenever I'm adding controls to a view that should appear together with the view, right away, I put it in the ViewDidLoad method. Basically this method is called whenever the view was loaded into memory. So for example, if my view is a form with 3 labels, I would add the labels here; the view will never exist without those forms.)
2) ViewWillAppear: 这里通常不做视图的修改,而用来更新Form数据,就是给给form重新填入新数据,该页面从别的页面回来时更新。UIView的创建非常费时费力,因此到 viewWillAppear时,iphone已经蓄势待发地、兴冲冲地要去显示了,就不要在这个地方再干费时费力的事情了,纯更新数据就可以了。(I use ViewWillAppear usually just to update the data on the form. So, for the example above, I would use this to actually load the data from my domain into the form. Creation of UIViews is fairly expensive, and you should avoid as much as possible doing that on the ViewWillAppear method, becuase when this gets called, it means that the iPhone is already ready to show the UIView to the user, and anything heavy you do here will impact performance in a very visible manner (like animations being delayed, etc).)
3) ViewDidAppear: 最后,视图已经显示了,那这里可以做一些远程取数据的费时费力的工作。(Finally, I use the ViewDidAppear to start off new threads to things that would take a long time to execute, like for example doing a webservice call to get extra data for the form above.The good thing is that because the view already exists and is being displayed to the user, you can show a nice "Waiting" message to the user while you get the data.)
For more information about the how views are added to view hierarchies by a view controller, and the sequence of messages that occur, see “Responding to Display-Related Notifications”.
Note: 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
该方法通知视图控制器,它的视图已经被加入视图树
Discussion
我们可以重写该方法执行附加任务,实现如何显示出视图。重写必须调用 super 方法。
Note: 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.
posted on
2013-08-12 18:40bbsno
阅读(256)
评论(0)
编辑收藏举报
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步