ios view的几种加载函数的区别didFinishLaunchingWithOptions、initWithNibName:bundle、loadView、viewWillAppear

本文详细介绍了iOS应用的启动过程及视图控制器的重要生命周期方法,包括应用程序启动时的didFinishLaunchingWithOptions方法,视图控制器初始化的initWithNibName方法,以及视图加载、显示前后的配置方法等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

application:didFinishLaunchingWithOptions: is where you instantiate and set an
application’s root view controller.
This method gets called exactly once when the application has launched. Even if you go to
another app and come back, this method does not get called again. If you reboot your phone and
start the app again, application:didFinishLaunchingWithOptions: will get called again.
initWithNibName:bundle: is the designated initializer for UIViewController.
When a view controller instance is created, its initWithNibName:bundle: gets called once. Note
that in some apps, you may end up creating several instances of the same view controller class.
This method will get called once on each as it is created.
loadView: is overridden to create a view controller’s view programmatically.
• viewDidLoad can be overridden to configure views created by loading a NIB file. This method
gets called after the view of a view controller is created.
viewWillAppear: can be overridden to configure views created by loading a NIB file.
This method and viewDidAppear: will get called every time your view controller is moved on
screen. viewWillDisappear: and viewDidDisappear: will get called every time your view
controller is moved offscreen. So if you launch the app you are working on and hop back and
forth between Hypnosis and Reminder, BNRReminderViewController’s viewDidLoad method will
be called once, but viewWillAppear: will be called dozens of times.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值