启动屏幕:EXC_BAD_ACCESS在调用dismissModalViewControllerAnimated后延迟
问题描述:
我想为我的应用程序使用模式视图控制器创建1-2秒的splashcreen但是当我尝试关闭视图时,我的应用程序崩溃,访问错误不正确。所以在我的应用程序委托我有:启动屏幕:EXC_BAD_ACCESS在调用dismissModalViewControllerAnimated后延迟
- (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];
}
而这一切工作除了当hideSplash在2秒的应用程序崩溃与一个EXC_BAD_ACCESS后称为完美的罚款。如果我注释掉进行选择线后,像这样马上致电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 !!!!
问题解决了!非常感谢您指出out = D – katbyte 2010-08-31 00:00:14