Search code examples
iphoneios5ios4addsubviewsigabrt

IOS app works in 4.3 but crashes with SIGABRT in main on 5.0


I was developing an app for iOS 4.3 back in the summer on my iPhone 4 and things were working well. I put that project on the back burner while I was relocating jobs. With the release of iOS 5 I updated both my Xcode and iOS SDK to 4.2 and 5.0 respectively and I also bought a new iPod Touch running 5.0 for developing.

My app still works in the iPhone 4.3 Simulator (unfortunately I don't have the iPhone 4 to test on anymore), but it crashes consistently on the iPhone 5.0 Simulator, as well as the iPod Touch.

The error happens when I try to load a subview and goes to main and says it crashes with a SIGABRT. Below is the segment of code where the crash occurs:

-(IBAction) showView:(id) sender{   
    if (self.tViewController == nil) {
        self.tViewController = [[TViewController alloc] init];
    }

    [self.navigationController pushViewController:tViewController animated:YES];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:.75];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
                         forView:self.view
                         cache:YES];

    [self.view addSubview:tViewController.view];
    [UIView commitAnimations];
}

When I step through and reach this line:

[self.view addSubview:tViewController.view];

It crashes, and jumps to main.m:

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

And shows a 'SIGABRT' being received at this line:

int retVal = UIApplicationMain(argc, argv, nil, nil);

I've read that the error is coming from something being released twice. But in my 'showView' function, I don't see where I could have done that. Unless the addSubview method does something I'm unaware of.

Also, why is this error happening in 5.0 and not 4.3?

Any help is appreciated.


Solution

  • -(IBAction) showView:(id) sender{   
        if (self.tViewController == nil) {
            self.tViewController = [[TViewController alloc] init];
        }
    
        [self.navigationController pushViewController:tViewController animated:YES];
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:.75];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
                         forView:self.view
                         cache:YES];
    
        [self.view addSubview:tViewController.view];
        [UIView commitAnimations];
    }
    

    You have already push this view using [self.navigationController pushViewController:tViewController animated:YES] then why are you adding it to main view using [self.view addSubview:tViewController.view] remove this line of code.