UIViewController 中的哪个方法应该完成“填充数据”的工作供查看?

发布于 2024-11-08 04:27:06 字数 94 浏览 0 评论 0原文

我对 ios 开发世界还很陌生。只是想知道我应该总是在 viewDidLoad 方法中执行此操作吗? 另外,总是在 viewDidUnload 中释放它是一个好主意吗?谢谢。

I am pretty fresh in ios dev world. just wondering should I always do it in viewDidLoad method?
Also is it a good idea to always release it in viewDidUnload? Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

糖果控 2024-11-15 04:27:06

Usually either in awakeFromNib, viewDidLoad, or viewWillAppear. Beginners usually start by putting everything in viewDidLoad which is fine for a simple view but there are reasons to use the other methods.

awakeFromNib is called when the nib is unpacked. Here you can add any additional views or set attributes that aren't available in IB. If you're not using IB then this doesn't get called.

viewDidLoad is called when the "view" is loaded (obvio). This should be used for adding view objects (typically subclasses of UIView) or updating them with current data. Any objects allocated here should be released in viewDidUnload (which may be called when memory is low). This gets called when a view is put into a window (triggered by UIViewController's view getter method) and isn't currently loaded (views get unloaded on a memory warning if they are not currently visible).

viewWillAppear is called anytime the view is going to appear in the window. This is the best place to update the data in your view with current data. This always gets called when you return from another modal view or pop another view controller or switch back to this app from the background or come back from a phone call, etc. Make sure you data is updated here or you may be showing stale data. Be sure to call [super viewWillAppear] at some point in this method.

See also these SO answers: here and here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文