且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

升级到iOS 4.2后,应用程序在启动时显示白屏

更新时间:2023-01-26 10:58:02

有人请枪杀我...

在我从《 iPhone开发者手册》中写下的一段代码的帮助下,才发现问题所在.

Just found the problem, with the help from a piece of code I had written down from the iPhone Developer's Cookbook.

问题不是SoundManager(幸运的是,它仍然可以正常工作),而是在App Delegate类的application:didFinishLaunchingWithOptions:方法中.

The problem was not the SoundManager (which still works fine, fortunately!) but in the application:didFinishLaunchingWithOptions: method in the App Delegate class.

以下是在iOS 4.2中引起问题的代码,但仍在iOS 3.2中有效:

Here is the code that causes the problem in iOS 4.2 but still works in iOS 3.2:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

// Create a Navigation Controller on the fly.
// Use the View Controller as root view controller.
viewController.title = @"ThreeSounds";

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
nav.navigationBar.barStyle = UIBarStyleBlack;

// Add the view controller's view to the window and display.
[window addSubview:nav.view];
[nav release];

[window makeKeyAndVisible];

return YES;
} 

解决方案:删除以下行:[nav release]. 由于某些原因,释放导航控制器在iOS 3.2中不是问题. 在iOS 4.2中,屏幕变白了.

The solution: remove the line that says: [nav release]. For some reason, releasing the navigation controller was not a problem in iOS 3.2. In iOS 4.2 is makes the screen go white.

我发现此方法是问题所在,因为它是最后执行的方法.反过来,我通过将这段代码添加到项目中的每个类中来找出答案:

I found out that this method was the problem because it was the last method that was executed. That, in turn, I found out by adding this piece of code to every class in my project:

-(BOOL) respondsToSelector:(SEL)aSelector {
 printf("SELECTOR: %s\n", [NSStringFromSelector(aSelector) UTF8String]);
 return [super respondsToSelector:aSelector];
}

这段代码记录了所有被调用的方法.

This piece of code logs all the methods that get called.