I have a LoginViewController
class that extends UIViewController
that is only displaying for a fraction of a second. In my AppDelegate.m
class I try to allocate a UINavigationController
that will have LoginViewController
as a child view controller. I see loginViewController
's view for a split second before the view goes black (I see the view I designed in Interface Builder). I'm not really sure why this is occurring.
Aside from the view flashing quickly, I was running the app on a 2nd gen iPod touch and noticed I could swipe my thumb to the right and see apps from the home screen. One more swipe and I could see search, but icons at the bottom such as music, mail, safari, and videos were not visible. Pressing stop button killed the app and returned to a normal home screen. This makes me think I'm setting the root view controller incorrectly? I took the if respondsToSelector
code from another question here on Stack Overflow. The if stopped my code from crashing which I think has something to do with devices older than iOS 4? When it ran without crashing is when I started receiving login view flashing just once and the home screen apps are just a thumb swipe away.
Any help is appreciated. If more of my code would help explain my question just let me know and I'll post more.
Edit: Forgot to post Xcode Version 4.4 and Deployment iOS targeted 4.0
AppDelegate.m
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
mainViewController = [[[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil] autorelease];
loginViewController = [[[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil] autorelease];
navigationController = [[UINavigationController alloc] init];
[navigationController pushViewController:loginViewController animated:NO];
if([window respondsToSelector:@selector(setRootViewController:)])
{
[window setRootViewController:navigationController];
}
else
{
[window addSubview:[navigationController view]];
}
initWithRootViewController:viewController] autorelease];
initWithNibName:@"ContainerViewController" bundle:nil] autorelease];
[window makeKeyAndVisible];
return YES;
}
Take out the autorelease
in your window-creating line. You want the window to live as long as the application is running.