Doesn't [UIWindow addSubView:] retain?
- by Dan Ray
Check it:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"Checking login--user value is %@", [defaults valueForKey:@"userID"]);
if ([defaults valueForKey:@"userID"] == NULL){
LoginViewController *loginController = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil];
[window addSubview:loginController.view];
[loginController release];
}
else {
[window addSubview:[navigationController view]];
}
Every other place when I put a subview into another view, I release that view after I've done that, because it's now owned by the view it's a subview of. HERE, though, when I do [loginController release], every IBAction on that loginController gets called against a deallocated instance. Commenting out that line makes everything work.
I note the difference in approach between my loginController and the navigationController that came with the template; the navigationController is a synthesized property that gets released in -(void)dealloc{ }, so it's still around after being put into window.