Application crash when using an NSTimer and pushViewController

Posted by Cesar on Stack Overflow See other posts from Stack Overflow or by Cesar
Published on 2010-06-03T07:38:01Z Indexed on 2010/06/03 7:44 UTC
Read the original article Hit count: 403

Filed under:

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

© Stack Overflow or respective owner

Related posts about iphone-sdk