Application crash when using an NSTimer and pushViewController
- by Cesar
I'm using an NSTimer to implement a 3 seconds splash screen. If a don't use a timer the view it's correctly pushed but if I use the timer for adding a little delay the application crash with a EXC_BAD_ACCESS.
I'm pretty sure the answer contains "memory management" but I can't get the point...
@interface RootViewController : UIViewController {
NSTimer *timer;
}
-(void)changeView:(NSTimer*)theTimer;
@property(nonatomic,retain) NSTimer *timer;
...
@implementation RootViewController
@synthesize timer;
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[self navigationController] setNavigationBarHidden:YES];
timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(changeView:) userInfo:nil repeats:NO];
}
-(void)changeView:(NSTimer*)theTimer
{
NSLog(@"timer fired");
//Crash here, but only if called using a timer
[[self navigationController] pushViewController:list animated:YES];
}