Question

Possible Duplicate:
show a login screen before Tab bar controller?

i am designing an iphone application which should be display login screen initially, after that it should display tab bar controller with 5 tabs. Am able to launch login screen initially, but when the login button is clicked am unble to show tab bar controller, kindly help me out with the code. here is my code: this is a view based application. Here is my code:

delegate.h

@interface iphoneAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;

     IphineViewController *viewController;
    IBOutlet UITabBarController *aTabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet IphoneViewController *viewController;

@property (nonatomic, retain) IBOutlet UITabBarController *aTabBarController;

@end

delegate.M

-(void)applicationDidFinishLaunching:(UIApplication *)application {  

// Override point for customization after app launch 

   [window addSubview:viewController.view]; 

   [window makeKeyAndVisible];

   LoginView *loginView=[[LoginView alloc]initWithNibName:@"LoginView" bundle:nil];

   [window addSubview:loginView.view];

}

loginView.M

TabBarController *tabBarController = [[TabBarController alloc]initWithNibName:@"TabBarController" bundle:nil];

    [self.view addSubView: tabBarController.view];


    [tabBarController release];

my question is:

1)can i use tab bar controller in the login view. I have declared ta bar in the delegate.h If this not correct how to use tab bar controller in my loginview.m

Was it helpful?

Solution

I think you have chosen wrong application layout. You should choose window based application. Then what you need to do is that first you set your login screen in the window of application and then once the login button is pressed you set your tabbar controller in the window of application. Just try it.

OTHER TIPS

You need to choose TabBarBased Application.From that it will automatically create a tabBarController object in your appDelegate and set that tabBarController.view in addSubview method. What you need to change is in AppDeleagte DidFinishLaunching method

create your login view controller object

then [window addSubview:loginviewcontroller.view];

Make a method in appDelegate as:-

-(void)loadTabBarControllerView
{
[[loginviewcontroller view]removeFromSuperview];
[window addSubview:tabBarController.view];
}

And on your login button click do(call loadTabBarControllerView method of appDelegate)

[*appDelegateobject* loadTabBarControllerView];

To show the login view in navigation based application you should try following instructions :

You just need to modify your RootViewController to be a subclass of UIVeiwController instead of UITableViewController, and modify the xib file to have a normal UIView as its view instead of a UITableView.

Then put following function to set tabbar:

-(void)setTabbar:(UIView *) view 
{
UIButton *btn1,*btn2,*btn3,*btn4,*btn5,*btn6;
UIView *tabView;

        tabView=[[UIView alloc]initWithFrame:CGRectMake(0, 375, 320, 44)];
        btn1=[UIButton buttonWithType:UIButtonTypeCustom];
        btn1.frame=CGRectMake(0, 0, 53, 44);
        btn1.tag=1;
        [btn1 setImage:[UIImage imageNamed:@"b1.png"] forState:UIControlStateNormal];
        [btn1 setImage:[UIImage imageNamed:@"b2.png"] forState:UIControlStateSelected];
        [btn1 addTarget:self action:@selector(btnTabclick::) forControlEvents:UIControlEventTouchDown];
        [tabView addSubview:btn1];


        btn2=[UIButton buttonWithType:UIButtonTypeCustom];
        btn2.frame=CGRectMake(53, 0, 53, 44);
        btn2.tag=2;
        [btn2 setImage:[UIImage imageNamed:@"b1.png"] forState:UIControlStateNormal];
        [btn2 setImage:[UIImage imageNamed:@"b2.png"] forState:UIControlStateSelected];
        [btn2 addTarget:self action:@selector(btnTabclick::) forControlEvents:UIControlEventTouchDown];
        [tabView addSubview:btn2];

        btn3=[UIButton buttonWithType:UIButtonTypeCustom];
        btn3.frame=CGRectMake(106, 0, 53, 44);
        btn3.tag=3;
        [btn3 setImage:[UIImage imageNamed:@"b1.png"] forState:UIControlStateNormal];
        [btn3 setImage:[UIImage imageNamed:@"b1.png"] forState:UIControlStateSelected];
        [btn3 addTarget:self action:@selector(btnTabclick::) forControlEvents:UIControlEventTouchDown];
        [tabView addSubview:btn3];

        btn4=[UIButton buttonWithType:UIButtonTypeCustom];
        btn4.frame=CGRectMake(159, 0, 55, 44);
        btn4.tag=4;
        [btn4 setImage:[UIImage imageNamed:@"b1.png"] forState:UIControlStateNormal];
        [btn4 setImage:[UIImage imageNamed:@"b1.png"] forState:UIControlStateSelected];
        [btn4 addTarget:self action:@selector(btnTabclick::) forControlEvents:UIControlEventTouchDown];
        [tabView addSubview:btn4];

        btn5=[UIButton buttonWithType:UIButtonTypeCustom];
        btn5.frame=CGRectMake(214, 0, 54, 44);
        btn5.tag=5;
        [btn5 setImage:[UIImage imageNamed:@"b1.png"] forState:UIControlStateNormal];
        [btn5 setImage:[UIImage imageNamed:@"b2.png"] forState:UIControlStateSelected];
        [btn5 addTarget:self action:@selector(btnTabclick::) forControlEvents:UIControlEventTouchDown];
        [tabView addSubview:btn5];

        btn6=[UIButton buttonWithType:UIButtonTypeCustom];
        btn6.frame=CGRectMake(266, 0, 55, 44);
        btn6.tag=6;
        [btn6 setImage:[UIImage imageNamed:@"b1.png"] forState:UIControlStateNormal];
        [btn6 setImage:[UIImage imageNamed:@"b2.png"] forState:UIControlStateSelected];
        [btn6 addTarget:self action:@selector(btnTabclick::) forControlEvents:UIControlEventTouchDown];
        [tabView addSubview:btn6];


if (TAG==1) 
{
    [btn1 setSelected:YES];
}
if (TAG==2) 
{
    [btn2 setSelected:YES];
}
if (TAG==3) 
{
    [btn3 setSelected:YES];
}
if (TAG==4) 
{
    [btn4 setSelected:YES];
}
if (TAG==5) 
{
    [btn5 setSelected:YES];
}
if (TAG==6) 
{
    [btn6 setSelected:YES];
}

[view addSubview:tabView];

if ([btnArry count]!=0 || [btnArry retainCount]!=0) 
{
    [btnArry release];
}

btnArry=[[NSArray alloc]initWithObjects:btn1,btn2,btn3,btn4,btn5,btn6, nil ];  
}

Then for handling button click event put following function

-(IBAction)btnTabclick:(id)sender:(UIView*)view
{
  TAG=[sender tag];
if (TAG==1) {
    //code to handle click event    

}else if(TAG==2){
    //code to handle click event  
}else if(TAG==3){
    //code to handle click event
}else if(TAG==4){
    //code to handle click event  
}else if(TAG==5){
    //code to handle click event    
}else if(TAG==6){
  //code to handle click event
}
 }

After putting above code in app delegate file just call the settabbar function as follow :

[((AppDelegate *)[[UIApplication sharedApplication]delegate]) setTabbar:self.view];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top