在Tab栏控制器之前显示登录屏幕

时间:2011-12-15 06:23:28

标签: iphone iphone-sdk-3.0 iphone-sdk-3.2 iphone-sdk-3.1.2

  

可能重复:
  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中使用标签栏控制器

3 个答案:

答案 0 :(得分:1)

我认为您选择了错误的应用程序布局。您应该选择基于窗口的应用程序然后你需要做的是首先在应用程序窗口中设置登录屏幕,然后按下登录按钮后,在应用程序窗口中设置tabbar控制器。试试吧。

答案 1 :(得分: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
}
 }

将以上代码放入app委托文件后,只需调用settabbar函数,如下所示:

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

答案 2 :(得分:0)

您需要选择TabBarBased Application。然后,它会自动在tabBarController中创建appDelegate对象,并在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按钮上点击执行(调用loadTabBarControllerView的{​​{1}}方法)

appDelegate