2011-12-15 307 views
0

可能重複:
show a login screen before Tab bar controller?顯示登錄屏幕

我設計應該是顯示登錄屏幕最初,在此之後它應該顯示選項卡欄控制器iPhone應用程序有5個標籤。我可以在最初啓動登錄屏幕,但是當單擊登錄按鈕時,我無法顯示標籤欄控制器,請幫助我解決代碼問題。這裏是我的代碼:這是一個基於視圖的應用程序。這裏是我的代碼:

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]; 

我的問題是:

1)可我在標籤欄控制器中使用登錄視圖。我已經在delegate.h中聲明瞭ta bar 如果這不正確如何在我的loginview.m中使用標籤欄控制器

+0

你需要接受的答案你前面的問題,令人沮喪的人把精力回答你的問題,如果你不能打擾接受他們的答案。 – 2011-12-15 11:18:38

回答

1

我認爲您選擇了錯誤的應用程序佈局。您應選擇基於窗口的應用程序。然後,您需要做的是首先在應用程序窗口中設置登錄屏幕,然後一旦登錄按鈕被按下,您就可以在應用程序窗口中設置TabBar控制器。去嘗試一下。

0

要顯示在基礎的導航應用程序的登錄視圖,你應該嘗試以下操作:

你只需要修改你的RootViewController的是UIVeiwController代替的UITableViewController的子類,並修改XIB文件有一個正常的UIView作爲它的視圖而不是UITableView。

然後把下面的函數來設置的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 ]; 
} 

然後把下面的函數

-(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 
} 
} 

把上面的代碼在應用程序委託文件後只需調用settabbar功能如下:

[((AppDelegate *)[[UIApplication sharedApplication]delegate]) setTabbar:self.view]; 
+0

u能告訴我該怎麼做?與之形成鮮明 – 2011-12-15 07:06:29

0

您需要選擇TabBarBased Application。由此它會自動在appDelegate中創建一個tabBarController對象,並將其設置爲tabBarController.view,方法爲addSubview。 你需要改變什麼是AppDeleagte DidFinishLaunching method

創建login view controller object

然後[window addSubview:loginviewcontroller.view];

請在appDelegate的方法如下: -

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

並在您login按一下按鈕做(電話的appDelegateloadTabBarControllerView方法)

[*appDelegateobject* loadTabBarControllerView];