希望了解iOS UIViewController的生命周期 [英] Looking to understand the iOS UIViewController lifecycle

查看:102
本文介绍了希望了解iOS UIViewController的生命周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能解释一下管理 UIViewController 生命周期的正确方法吗?

Could you explain me the correct manner to manage the UIViewController lifecycle?

特别是,我想知道如何使用初始化 ViewDidLoad ViewWillAppear ViewDidAppear ViewWillDisappear ViewDidDisappear ViewDidUnload 在Mono Touch中为 UIViewController 类配置方法。

In particular, I would like to know how to use Initialize, ViewDidLoad, ViewWillAppear, ViewDidAppear, ViewWillDisappear, ViewDidDisappear, ViewDidUnload and Dispose methods in Mono Touch for a UIViewController class.

推荐答案

当您加载/显示/隐藏视图控制器时,iOS会在适当的时间自动调用所有这些命令。重要的是要注意这些方法附加到 UIViewController 而不是 UIView s本身。只使用 UIView ,您将无法获得任何这些功能。

All these commands are called automatically at the appropriate times by iOS when you load/present/hide the view controller. It's important to note that these methods are attached to UIViewController and not to UIViews themselves. You won't get any of these features just using a UIView.

Apple网站上有很棒的文档这里。简单地说:

There's great documentation on Apple's site here. Putting in simply though:


  • ViewDidLoad - 创建时调用从xib加载类和加载。非常适合初始设置和一次性工作。

  • ViewDidLoad - Called when you create the class and load from xib. Great for initial setup and one-time-only work.

ViewWillAppear - 在您的观看之前调用出现,适用于隐藏/显示字段或每次在视图可见之前发生的任何操作。因为您可能会在视图之间来回切换,所以每次您的视图即将出现在屏幕上时都会调用此视图。

ViewWillAppear - Called right before your view appears, good for hiding/showing fields or any operations that you want to happen every time before the view is visible. Because you might be going back and forth between views, this will be called every time your view is about to appear on the screen.

ViewDidAppear - 在视图出现后调用 - 开始制作动画或从API加载外部数据的好地方。

ViewDidAppear - Called after the view appears - great place to start an animations or the loading of external data from an API.

ViewWillDisappear / DidDisappear - 与相同的想法ViewWillAppear / ViewDidAppear

ViewWillDisappear/DidDisappear - Same idea as ViewWillAppear/ViewDidAppear.

ViewDidUnload / ViewDidDispose - 在Objective C中,这是你清理和发布东西的地方,但这是自动处理的,所以你真的不需要在这里做。

ViewDidUnload/ViewDidDispose - In Objective C, this is where you do your clean-up and release of stuff, but this is handled automatically so not much you really need to do here.

这篇关于希望了解iOS UIViewController的生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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