next view controller is not appearing when i launched apps - iphone

I am getting NSLog message when i am runing apps but nextviewcontroller(welcome page)is not appearing, i want to call nextviewcontroller first time that have a action continue .this screen will appear first time only when we run first time. Condition is working but nextviewcontroller is not coming .I used this code so for
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Configure logging framework
[DDLog addLogger:[DDTTYLogger sharedInstance]];
// Setup the XMPP stream
[self setupStream];
// Override point for customization after application launch.
BOOL launch = [[NSUserDefaults standardUserDefaults] boolForKey:#"LaunchingFirstTime"];
if(!launch){
NSLog(#"first");
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"LaunchingFirstTime"];
[[NSUserDefaults standardUserDefaults] synchronize];
self.viewController1 = [[welcomePage alloc] initWithNibName:#"welcomePage" bundle:nil];
self.window.rootViewController = self.viewController1;
}
else{
NSLog(#"second");
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
}
[self.window makeKeyAndVisible];
if (![self connect])
{
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.0 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//messageTableViewController
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
//[navigationController presentModalViewController:settingsViewController animated:YES];
});
}
return YES;

If you are not using story boards and if your window is not an IBOutlet do this.
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//add this
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor=[UIColor clearColor];
BOOL launch = [[NSUserDefaults standardUserDefaults] boolForKey:#"LaunchingFirstTime"];
if(!launch){
NSLog(#"first");
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"LaunchingFirstTime"];
self.viewController1 = [[welcomePage alloc] initWithNibName:#"welcomePage" bundle:nil];
self.window.rootViewController = self.viewController1;
}
else{
NSLog(#"second");
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
BOOL launch = [[NSUserDefaults standardUserDefaults] boolForKey:#"LaunchingFirstTime"];
if(!launch){
NSLog(#"first");
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"LaunchingFirstTime"];
[[NSUserDefaults standardUserDefaults] synchronize];
self.viewController1 = [[welcomePage alloc] initWithNibName:#"welcomePage" bundle:nil];
self.window.rootViewController = self.viewController1;
} else {
NSLog(#"second");
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
}
}

If you are using UIStoryBoard , Then try with this
`instantiateViewControllerWithIdentifier` .: application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
BOOL launch = [[NSUserDefaults standardUserDefaults] boolForKey:#"LaunchingFirstTime"];
if(!launch){
NSLog(#"first");
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"LaunchingFirstTime"];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
ViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:#"ViewController_ID"];
self.window.rootViewController = self.viewController1;
}
else{
NSLog(#"second");
self.viewController = // Follow the above
self.window.rootViewController = self.viewController;
}
If you are not working with the Storyboard then please describe your problem briefly` ,.

Use synchronize method to make the user defaults get written on disk immediately.
[[NSUserDefaults standardUserDefaults] synchronize];
From Apple Docs:
synchronize method writes any modifications to the persistent domains to disk and updates all unmodified persistent domains to what is on disk.
It is missing in your code. Write it in if clause.

Related

how to check wether app is logged in or not first time [duplicate]

This question already has answers here:
How to detect first time app launch on an iPhone
(17 answers)
Closed 9 years ago.
I want the when user install apps on device app should show him loginScreen when user first time opens app after that user logins and user remains logins is there any way to make this save so that if user again opens app second then user should be in logged stated and does not show user the login screen thanks.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch.
self.splitViewController =[[UISplitViewController alloc]init];
self.rootViewController=[[RootViewController alloc]init];
self.detailViewController=[[[FirstDetailViewController alloc]init] autorelease];
self.loginViewController=[[[LoginViewController alloc]init] autorelease];
UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController];
UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController];
if ([detailNav.navigationBar respondsToSelector:#selector(setBackgroundImage:forBarMetrics:)] )
{
UIImage *image = [UIImage imageNamed:#"Nav.png"];
[detailNav.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
user_Name=#"Jamshaid";
isClickedLogin=#"NO";
userLogin=#"Logout";
self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil];
self.splitViewController.delegate=self.detailViewController;
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
self.coffeeArray = tempArray;
[tempArray release];
NSMutableArray *tempArray1 = [[NSMutableArray alloc] init];
self.arrayOne = tempArray1;
[tempArray1 release];
NSMutableArray *tempArray2 = [[NSMutableArray alloc] init];
self.arrayTwo = tempArray2;
[tempArray2 release];
NSMutableArray *tempArray3 = [[NSMutableArray alloc] init];
self.libraryArray = tempArray3;
[tempArray3 release];
NSMutableArray *tempArray4 = [[NSMutableArray alloc] init];
self.activityArray = tempArray4;
[tempArray4 release];
NSMutableArray *tempArray5 = [[NSMutableArray alloc] init];
self.arrayOneC = tempArray5;
[tempArray5 release];
NSMutableArray *tempArray6 = [[NSMutableArray alloc] init];
self.arrayTwoC = tempArray6;
[tempArray6 release];
NSMutableArray *tempArrayD = [[NSMutableArray alloc] init];
self.detailArray = tempArrayD;
[tempArrayD release];
NSMutableArray *tempArrayD1 = [[NSMutableArray alloc] init];
self.detailArrayOne = tempArrayD1;
[tempArrayD1 release];
NSMutableArray *tempArrayD2 = [[NSMutableArray alloc] init];
self.detailArrayTwo = tempArrayD2;
[tempArrayD2 release];
NSMutableArray *tempArrayD3 = [[NSMutableArray alloc] init];
self.publishArray = tempArrayD3;
[tempArrayD3 release];
[Coffee getInitialDataToDisplay:[self getDBPath]];
// Add the split view controller's view to the window and display.
// original working [window addSubview:self.splitViewController.view];
[window addSubview:splitViewController.view];
[window makeKeyAndVisible];
return YES;
}
I don't do iPhone development, but wouldn't this easily be achieved using a config file? For example:
App start
read config.xml
is element firstlogin false or true?
if true: show the loginscreen, once the user logs in, set element to true and save the xml.
if false: don't edit the xml at all and just skip the loginscreen.
run app
This would, of course, reset if the app is reinstalled, I figure.
Sample Code :
In yourViewController.h :
NSString *uname;
NSString *pwd;
In yourViewController.m :
- (IBAction) loginButtonClicked :(id)sender
{
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"HasLaunchedOnce"])
{
// app already launched
uname = [[NSUserDefaults standardUserDefaults] valueForKey:#"UserName"];
pwd = [[NSUserDefaults standardUserDefaults] valueForKey:#"PassWord"];
//Use uname and pwd in your URL.
}
else
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
// This is the first launch ever
[[NSUserDefaults standardUserDefaults] setValue:txtUserName.text forKey:#"UserName"];
[[NSUserDefaults standardUserDefaults] setValue:txtPassWord.text forKey:#"PassWord"];
}
}

Custom TabbarController in Windowbase Application

Hi friend I want to Develop an application for windows base First page of the loading page then after the next view i want to add UitabbarController. i have implement this code.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
flag=1;
splash *objSplash=[[splash alloc]initWithNibName:#"splash" bundle:nil];
Home *placeholder1 = [[Home alloc] initWithNibName:#"Home" bundle:nil];
placeholder1.title=#"Home";
placeholder1.tabBarItem.image=[UIImage imageNamed:#"home1.png"];
shopHome *placeholder2 = [[shopHome alloc] initWithNibName:#"shopHome" bundle:nil];
placeholder2.title=#"Store";
placeholder2.tabBarItem.image=[UIImage imageNamed:#"Shop.png"];
Search1 *placeholder3 = [[Search1 alloc] initWithNibName:#"Search1" bundle:nil];
placeholder3.title=#"Search";
placeholder3.tabBarItem.image=[UIImage imageNamed:#"search2.png"];
info *placeholder4 = [[info alloc]initWithNibName:#"info" bundle:nil];
placeholder4.title=#"Info";
placeholder4.tabBarItem.image=[UIImage imageNamed:#"info1.png"];
CartView *placeholder5=[[CartView alloc]initWithNibName:#"CartView" bundle:nil];
placeholder5.title=#"Cart";
placeholder5.tabBarItem.image=[UIImage imageNamed:#"Cart.png"];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] init];
UINavigationController *localNavController;
localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder1];
localNavController.navigationBar.tintColor=[UIColor blackColor];
// Add navigation controller to the local vc array (1 of 2)
[localViewControllersArray addObject:localNavController];
[localNavController release];
localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder2];
[localViewControllersArray addObject:localNavController];
[localNavController release];
localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder3];
[localViewControllersArray addObject:localNavController];
[localNavController release];
if(flag==1)
{
localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder5];
[localViewControllersArray addObject:localNavController];
[localNavController release];
}
localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder4];
[localViewControllersArray addObject:localNavController];
[localNavController release];
tabBarController = [[UITabBarController alloc] init];
//tabBarController.viewControllers = [NSArray arrayWithObjects:placeholder1, placeholder2, placeholder3, placeholder4, nil];
tabBarController.viewControllers = localViewControllersArray;
//tabBarController.tintColor=[UIColor colorWithRed:160/256.0 green:82/256.0 blue:45/256.0 alpha:1.0];
//tabBarController.tabBar.backgroundColor=[UIColor colorWithRed:160/256.0 green:82/256.0 blue:45/256.0 alpha:1.0];
tabBarController.delegate=self;
[placeholder1 release];
[placeholder2 release];
[placeholder3 release];
[placeholder4 release];
[self.window addSubview:objSplash.view];
//[self.window addSubview:navigationController.view];
//[self.window addSubview:tabBarController.view];
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:#selector(goToNext) userInfo:nil repeats:NO];
flag=1;
[self parsingData];
[window makeKeyAndVisible];
return YES;
}
-(void)goToNext
{
//[self.navigationController.view addSubview:tabBarController.view];
[self.window addSubview:tabBarController.view];
}
Simply try to implement this one :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
splash *objSplash=[[splash alloc]initWithNibName:#"splash" bundle:nil];
Home *placeholder1 = [[Home alloc] initWithNibName:#"Home" bundle:nil];
placeholder1.title=#"Home";
placeholder1.tabBarItem.image=[UIImage imageNamed:#"home1.png"];
shopHome *placeholder2 = [[shopHome alloc] initWithNibName:#"shopHome" bundle:nil];
placeholder2.title=#"Store";
placeholder2.tabBarItem.image=[UIImage imageNamed:#"Shop.png"];
Search1 *placeholder3 = [[Search1 alloc] initWithNibName:#"Search1" bundle:nil];
placeholder3.title=#"Search";
placeholder3.tabBarItem.image=[UIImage imageNamed:#"search2.png"];
info *placeholder4 = [[info alloc]initWithNibName:#"info" bundle:nil];
placeholder4.title=#"Info";
placeholder4.tabBarItem.image=[UIImage imageNamed:#"info1.png"];
CartView *placeholder5=[[CartView alloc]initWithNibName:#"CartView" bundle:nil];
placeholder5.title=#"Cart";
placeholder5.tabBarItem.image=[UIImage imageNamed:#"Cart.png"];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] init];
UINavigationController *localNavController;
localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder1];
localNavController.navigationBar.tintColor=[UIColor blackColor];
// Add navigation controller to the local vc array (1 of 2)
[localViewControllersArray addObject:localNavController];
[localNavController release];
localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder2];
[localViewControllersArray addObject:localNavController];
[localNavController release];
localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder3];
[localViewControllersArray addObject:localNavController];
[localNavController release];
if(flag==1)
{
localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder5];
[localViewControllersArray addObject:localNavController];
[localNavController release];
}
localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder4];
[localViewControllersArray addObject:localNavController];
[localNavController release];
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = localViewControllersArray;
tabBarController.delegate=self;
[placeholder1 release];
[placeholder2 release];
[placeholder3 release];
[placeholder4 release];
[self.window addSubview:objSplash.view];
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:#selector(goToNext) userInfo:nil repeats:NO];
[window makeKeyAndVisible];
return YES;
}
-(void)goToNext
{
[self.window addSubview:tabBarController.view];
}
#implementation Home
- (id)initWithTitle:(NSString*)theTitle {
if (self = [super init]) {
self.tabBarItem.image = [UIImage imageNamed:#"Home.png"];
self.title = theTitle;
}
return self;
}
Note :
This is already tested solution hope it will work for you as well.

How to show a UIViewController on the First time Application Launch?

I want to know how to show a page on the very first time launch of the application,I had serch for these and get many code but in my case its not working for me, I have this code in DidFinishLaunching Method,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],#"firstLaunch",nil]];
//If First Launch
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"firstLaunch"]) {
//Show help view
UIScrollView_PagingViewController *detailViewController = [[UIScrollView_PagingViewController alloc] initWithNibName:#"UIScrollView_PagingViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
else {
NSError *error = nil;
NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:#"username"];
NSString *str = [SFHFKeychainUtils getPasswordForUsername:username andServiceName:#"mybibleapp" error:&error];
NSLog(#"previous user");
NSLog(#"%#", str);
if (!error && nil != str)
{
ParallelReadViewController *detailViewController = [[ParallelReadViewController alloc] initWithNibName:#"ParallelReadViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
else
{
RootViewController *detailViewController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
}
but when i run this code ,it shows a blank white screen ,nothing shows.
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],#"firstLaunch",nil]];
//If First Launch
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"firstLaunch"]) {
//Show help view
UIScrollView_PagingViewController *detailViewController = [[UIScrollView_PagingViewController alloc] initWithNibName:#"UIScrollView_PagingViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
else {
i put the above code for launch UIScrollView_PagingViewController to launch .but no luck.What is the mistake i made in the above code.?.please help me.
Thanks in advance.
You are trying to push that controller at very first time but at the roo there is no any controller. so you have to add in window first. then you can push the UIViewController
self.window.rootViewController = detailViewController.view;
don't release the viewController before use.
You are not placing the code in right place. Don’t put this code in AppDelegate try to keep your appdelegate as clean as possible for better #performance. Use some ViewController which will get call after splash screen and check if your code works there.
try this
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"firstLaunch"])
{
UIScrollView_PagingViewController *detailViewController =[[UIScrollView_PagingViewController alloc] initWithNibName:#"UIScrollView_PagingViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
self.navController=[[UINavigationController alloc] initWithRootViewController:detailViewController];
self.window.rootViewController=self.navController;
}
Just do a trcik,
Don’t put this code in AppDelegate try to keep your appdelegate as clean as possible for better performance.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES;
}
And Place this Code in you RootViewController
Everytime when the application will get launch, it check the condition in delegate method, instead will check in RootViewController.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],#"firstLaunch",nil]];
//If First Launch
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"firstLaunch"]) {
//Show help view
UIScrollView_PagingViewController *detailViewController = [[UIScrollView_PagingViewController alloc] initWithNibName:#"UIScrollView_PagingViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:NO];
[detailViewController release];
}
else {
NSError *error = nil;
NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:#"username"];
NSString *str = [SFHFKeychainUtils getPasswordForUsername:username andServiceName:#"mybibleapp" error:&error];
NSLog(#"previous user");
NSLog(#"%#", str);
if (!error && nil != str)
{
ParallelReadViewController *detailViewController = [[ParallelReadViewController alloc] initWithNibName:#"ParallelReadViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:NO];
[detailViewController release];
}
else
{
// RootViewController *detailViewController = [[RootViewController alloc] //initWithNibName:#"RootViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
// [self.navigationController pushViewController:detailViewController //animated:NO];
//[detailViewController release];
}
}

iPhone .ipa file goes blank after opening splash screen?

I have created Map application and it is running on my mac machine with xcode. But when I created its ipa file and sync with my iPhone device it does not open. Only splash screen
get open and getting close. I have my developer and distribution certificate sign with device UDID. My client also could not able to run the application remotely....thanks in advance for your help. plz suggest what I am missing here??
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//sleep(0.5);
arrayNo = [[NSMutableArray alloc] init]; //pickerview radius array
[arrayNo addObject:#"5km"];
[arrayNo addObject:#"10km"];
[arrayNo addObject:#"15km"];
[window addSubview:[viewController view]];
[window makeKeyAndVisible];
return YES;
}
Upadated: with leaks problems
I am also checking the possibility with memory leaks and using instrument tool I am getting 100% leaks at the time of launching the application. Its NSPlaceholderString leaks on following code...
CLLocationCoordinate2D location;
NSString *url = [NSString stringWithFormat:#"..myurl......lat=%f&lng=%f&radius=5",locationManager.location.coordinate.latitude,locationManager.location.coordinate.longitude];
radiusinurl.text = #"5km";
NSURL *URL = [NSURL URLWithString:url];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:URL];
//Initialize the delegate.
**XMLParser *parser = [[XMLParser alloc] initXMLParser];** //5.3% leaks
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
**BOOL success = [xmlParser parse];** //0.2% leaks
[xmlParser release];
[parser release];
if(success)
{
NSLog(#"show me [appDelegate.markers count] %d",[appDelegate.markers count]);
annobjs = [[NSMutableArray array] retain];
if([appDelegate.markers count] == 0)
{ //99% leaks on below line where I am calling another method
**[self performSelector:#selector(showingThreeResultsOnCurrentLocation) withObject:nil];** //99% leaks
}
else
{//some logic
}
}
else
{
//logic
}}}}
I have commented leaks at the end of line. Can you correct my code. Thanks in advance...
Initialize view controller first
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; //This is for autoresize when in phone call mode(which does not work yet)
[dict setObject:#"trigger" forKey:#"frame"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"trigger"
object:self
userInfo:dict];
arrayNo = [[NSMutableArray alloc] init]; //pickerview radius array
[arrayNo addObject:#"5km"];
[arrayNo addObject:#"10km"];
[arrayNo addObject:#"15km"];
viewController = [[UIViewController alloc] initWithNibName:#"UIViewController" bundle:nil];
UINavigationController *nav = [[UINavigaitonController alloc] initWithRootViewController:nav];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}

Putting a ViewController on top of a TabBarController

Basically I want to make a login screen in my iPhone app before I show my TabBarController. I tried the following approach, adding first to the window subview my TabBarController and on top my LoginViewController. What am I doing wrong or should I do it completely different?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
NSMutableArray *tabItems = [[NSMutableArray alloc] initWithCapacity:2];
DefaultViewController *dvc = [[DefaultViewController alloc] init];
UINavigationController *dvc_nc = [[UINavigationController alloc] initWithRootViewController:dvc];
dvc_nc.tabBarItem.title = #"Home";
//dvc_nc.tabBarItem.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Default" ofType:#"png"]];
[tabItems addObject:dvc_nc];
[dvc release];
[dvc_nc release];
OptionsViewController *ovc = [[OptionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
UINavigationController *ovc_nc = [[UINavigationController alloc] initWithRootViewController:ovc];
ovc_nc.tabBarItem.title = #"Option";
//ovc_nc.tabBarItem.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Option" ofType:#"png"]];
[tabItems addObject:ovc_nc];
[ovc release];
[ovc_nc release];
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = tabItems;
self.tabController = tbc;
[tabItems release];
[tbc release];
[self.window addSubview:self.tabController.view];
LoginViewController *lvc = [[OptionsViewController alloc] init];
UINavigationController *lvc_nc = [[UINavigationController alloc] initWithRootViewController:lvc];
[self.window addSubview:lvc_nc.view];
[lvc release];
[lvc_nc release];
return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
NSMutableArray *tabItems = [[NSMutableArray alloc] initWithCapacity:2];
DefaultViewController *dvc = [[DefaultViewController alloc] init];
UINavigationController *dvc_nc = [[UINavigationController alloc] initWithRootViewController:dvc];
dvc_nc.tabBarItem.title = #"Home";
//dvc_nc.tabBarItem.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Default" ofType:#"png"]];
[tabItems addObject:dvc_nc];
[dvc release];
[dvc_nc release];
OptionsViewController *ovc = [[OptionsViewController alloc] initWithStyle:UITableViewStyleGrouped];
UINavigationController *ovc_nc = [[UINavigationController alloc] initWithRootViewController:ovc];
ovc_nc.tabBarItem.title = #"Option";
//ovc_nc.tabBarItem.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Option" ofType:#"png"]];
[tabItems addObject:ovc_nc];
[ovc release];
[ovc_nc release];
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = tabItems;
self.tabController = tbc;
[tabItems release];
[tbc release];
[self.window addSubview:self.tabController.view];
LoginViewController *lvc = [[OptionsViewController alloc] init];
UINavigationController *lvc_nc = [[UINavigationController alloc] initWithRootViewController:lvc];
[self.tabController presentModalViewController:lvc_nc animated:no];
[lvc release];
[lvc_nc release];
return YES;
}
I would use two different views. One will handle the login proccess and one is your "Logged in view" that provides the features of your app. When your app starts up, you add the login view, check username/password and when the login went fine you switch to your second view.