【发布时间】:2011-06-29 17:23:24
【问题描述】:
任何 iOS 应用程序启动时首先调用哪个方法和函数?
【问题讨论】:
任何 iOS 应用程序启动时首先调用哪个方法和函数?
【问题讨论】:
我猜是
int main(int argc, char *argv[])
在main.m 文件中
但出于实际目的,我认为您通常需要根据情况实现一些 UIApplicationDelegate 的方法:
application:didFinishLaunchingWithOptions:
applicationDidBecomeActive:
applicationWillEnterForeground:
【讨论】:
如果一个 View 启动了,那么它是:
- (void)viewDidLoad {}
如果一个应用启动它是:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
或
- (void)applicationWillEnterForeground:(UIApplication *)application {
我认为你最好使用 ViewDidLoad 方法。
希望我能帮上忙!
【讨论】:
其实:
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions{}
出现在:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{}
【讨论】:
应用程序启动时,首先应用程序:didFinishLaunchingWithOptions: 方法被调用..
视图启动后
>此时 viewDidLoad 被执行;
【讨论】:
应用启动期间调用的第一个函数
int main(int argc, char *argv[])
应用启动期间调用的第一个方法
application(_:willFinishLaunchingWithOptions:)
UIKit 处理大部分应用启动任务。
1) The app is launched, either explicitly by the user or implicitly by the system.
2) The Xcode-provided main function calls UIKit's UIApplicationMain() function.
3) The UIApplicationMain() function creates the UIApplication object and your app delegate.
4) UIKit loads your app's default interface from the main storyboard or nib file.
5) UIKit calls your app delegate's application(_:willFinishLaunchingWithOptions:) method.
6) UIKit performs state restoration, which calls additional methods of your app delegate and view controllers.
7) UIKit calls your app delegate's application(_:didFinishLaunchingWithOptions:) method.
【讨论】:
Have look at image 根据苹果文档
在之前被调用
【讨论】: