我的应用程序正常运行。
但是,我在rootViewController的viewDidLoad方法的第一行放了一个断点,在我的委托的第一行放了另一个断点didFinishLaunchingWithOptions,
令我惊讶的是,应用程序在viewDidLoad方法中输入,然后转到didFinishLaunchingWithOptions,然后再执行一次viewDidLoad方法。
发生了什么事?我认为这种行为是完全错误的。
提前谢谢!
# 编辑这是我的iPad委托didFinishLaunchingWithOptions方法:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
UtilXML *utilXML = [[UtilXML alloc] init];
[utilXML startXMLCommunication];
int quantidadeDeComicsBaixadas = [utilXML quantidadaDeComicsBaixadas];
main_iPad *mainiPad = [[main_iPad alloc] init];
mainiPad.quantidadeDeComicsBaixadas = quantidadeDeComicsBaixadas;
mainiPad.navigationItem.title = @"TitleFirstScreen";
UIBarButtonItem *botaoSobre = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:mainiPad action:@selector(goToAboutView)];
mainiPad.navigationItem.rightBarButtonItem = botaoSobre;
navController = [[UINavigationController alloc] initWithRootViewController:mainiPad];
navController.navigationBar.tintColor = [UIColor orangeColor];
navController.navigationBar.translucent = YES;
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;
}
这是我的iPhone的委托didFinishLaunchingWithOptions方法:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
UtilXML *utilXML = [[UtilXML alloc] init];
[utilXML startXMLCommunication];
int quantidadeDeComicsBaixadas = [utilXML quantidadaDeComicsBaixadas];
main_iPhone *mainiPhone = [[main_iPhone alloc] init];
mainiPhone.quantidadeDeComicsBaixadas = quantidadeDeComicsBaixadas;
mainiPhone.navigationItem.title = @"TitleFirstScreen";
UIBarButtonItem *botaoSobre = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:mainiPhone action:@selector(goToAboutView)];
mainiPhone.navigationItem.rightBarButtonItem = botaoSobre;
navController = [[UINavigationController alloc] initWithRootViewController:mainiPhone];
navController.navigationBar.tintColor = [UIColor orangeColor];
navController.navigationBar.translucent = YES;
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;
}
这两种设备都会出现这种奇怪的行为。
答案 0 :(得分:8)
application:didFinishLaunchingWithOptions:
您应该使用此方法初始化您的应用程序并做好准备 它运行。在您的应用程序启动后调用它 并且已加载其主nib文件。当时这个方法是 调用后,您的应用程序处于非活动状态。在某些时候之后 此方法返回,调用后续委托方法移动 您的应用程序到活动(前景)状态或背景 状态。
因此,一旦调用view
属性或方法,视图就会为视图控制器延迟加载。当发生这种情况时{@ 1}被调用,所以如果您的窗口viewDidLoad
属性设置为nib中的根ViewController,那么这是预期的行为。