Заставка: EXC_BAD_ACCESS после вызова dismissModalViewControllerAnimated задерживается - PullRequest
0 голосов
/ 31 августа 2010

Я пытаюсь создать 1-2-секундный экран-заставку для своего приложения, используя модальный контроллер представления, однако, когда я пытаюсь отклонить представление, мое приложение вылетает с ошибкой неверного доступа.Итак, в моем делегате приложения у меня есть:

- (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];

Модальное представление корректно отклоняется.Я вполне уверен, что это проблема управления памятью, но я не уверен точно, что я делаю здесь неправильно.У кого-нибудь есть идеи о том, что это может быть или как правильно отладить это, чтобы я мог отложить увольнение?

Спасибо

Ответы [ 2 ]

1 голос
/ 25 июня 2011
//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 !!!!
1 голос
/ 31 августа 2010

Это выглядит странно:

mainViewCtrl = [MainViewController alloc];

Попробуйте добавить к нему вызов инициализации.

...