Iphone 启动屏幕:调用dismissModalViewControllerAnimated delayed后执行错误访问
我正在尝试使用模式视图控制器为我的应用程序创建一个1-2秒的飞溅屏幕,但是当我尝试关闭视图时,我的应用程序由于严重的访问错误而崩溃。因此,在我的申请委托中,我有:Iphone 启动屏幕:调用dismissModalViewControllerAnimated delayed后执行错误访问,iphone,exc-bad-access,Iphone,Exc Bad Access,我正在尝试使用模式视图控制器为我的应用程序创建一个1-2秒的飞溅屏幕,但是当我尝试关闭视图时,我的应用程序由于严重的访问错误而崩溃。因此,在我的申请委托中,我有: - (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //create window and show it window = [[UIWindow al
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//create window and show it
window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
window.backgroundColor = [UIColor greenColor];
[window makeKeyAndVisible];
//create the main view controller and add its view to the window
mainViewCtrl = [MainViewController alloc];
[window addSubview:mainViewCtrl.view];
//show splash screen
UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"default.png" ofType:nil]];
splashViewCtrl = [[UIViewController alloc] init];
splashViewCtrl.view = [[UIImageView alloc] initWithImage:image];
[mainViewCtrl presentModalViewController:splashViewCtrl animated:NO];
//setup callback to dismiss
[self performSelector:@selector(hideSplash) withObject:nil afterDelay:2.0];
return(true);
}
//hide splash screen callback
- (void)hideSplash {
[[self mainViewCtrl] dismissModalViewControllerAnimated:YES];
}
除了在2秒钟后调用hideSplash时,应用程序因EXC_BAD_访问而崩溃外,这一切都可以正常工作。如果我注释掉执行选择器行,然后立即调用hidesplash,就像这样:
[mainViewCtrl presentModalViewController:splashViewCtrl animated:NO];
[self hideSplash];
模态视图被正确地忽略。我相当肯定这是一个内存管理问题,但我不确定我到底做错了什么。有没有人知道这可能是什么,或者如何正确地调试它,以便我可以推迟解雇
谢谢这看起来很奇怪:
mainViewCtrl = [MainViewController alloc];
尝试向其添加初始化调用
//show splash screen
UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"default.png" ofType:nil]];
splashViewCtrl = [[UIViewController alloc] init];
splashViewCtrl.view = [[UIImageView alloc] initWithImage:image];
[mainViewCtrl presentModalViewController:splashViewCtrl animated:NO];
将上述内容更改为以下内容:
//show splash screen
UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"default.png" ofType:nil]];
splashViewCtrl = [[UIViewController alloc] init];
splashViewCtrl.view = [[UIImageView alloc] initWithImage:image];
[mainViewCtrl presentModalViewController:splashViewCtrl animated:NO];
[mainViewCtrl release]; //Add this line !!!!