Tab Bar Application Part 3 ( Add a login screen)
Step 1
Create a Project by using My Previous Tutorial Part 1 & Part 2
Step 2
create new class ... call " LoginView" to your project
design the " LoginView.xib " like this
Step 3
Click the "AppDelegate.m" and import the LoginView header
Step 4
change code like this... in "AppDelegate.m "
this is the method you have to change
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
code : -
//
// AppDelegate.m
// TabBarExample
//
// Created by Apple on
4/24/13.
// Copyright (c) 2013
Dhanushka Adrian. All rights reserved.
//
#import "AppDelegate.h"
#import "ViewController.h"
#import "FirstTabView.h"
#import "SecondTabView.h"
#import "ThirdTabView.h"
#import "LoginView.h"
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[_viewController release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override
point for customization after application launch.
FirstTabView *firstTab
=[[FirstTabView alloc]initWithNibName:@"FirstTabView" bundle:nil];
SecondTabView *secondTab
=[[SecondTabView alloc]initWithNibName:@"SecondTabView" bundle:nil];
ThirdTabView *thirdTab
=[[ThirdTabView alloc]initWithNibName:@"ThirdTabView" bundle:nil];
ViewController
*fourthTab =[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
UINavigationController *nav1 =[[UINavigationController alloc] initWithRootViewController:firstTab];
UINavigationController *nav2 =[[UINavigationController alloc] initWithRootViewController:secondTab];
UINavigationController *nav3 =[[UINavigationController alloc] initWithRootViewController:thirdTab];
UINavigationController *nav4 =[[UINavigationController alloc] initWithRootViewController:fourthTab];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nav4,
nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
// add this
code
LoginView
*logViewController = [[LoginView alloc] initWithNibName:@"LoginView" bundle:nil];
[self.window addSubview:_tabBarController.view];
//add this
code
[self.tabBarController presentModalViewController:logViewController
animated:YES];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
}
- (void)applicationWillTerminate:(UIApplication *)application
{
}
@end
Step 5
Add a method for login like this...
// LoginView.h
// TabBarExample
//
// Created by Apple on
4/24/13.
// Copyright (c)Dhanushka
Adrian. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LoginView : UIViewController
-(IBAction)Login:(id)sender;
@end
Step 6
click the "LoginView.m"
type this metod in "LoginView.m"....
-(IBAction)Login:(id)sender{
[self dismissModalViewControllerAnimated:YES];
}
Step 7
click the "LoginView.xib"
right click the file owner
Step 8
Run your App