5

アプリにタブバーコントローラーを実装しました。しかし、私の最初のページは Login View です。そのため、タブバーを表示したくありません。そのビューのタブバーを非表示にすることでこれを行いました。

しかし、今、最初のタブを選択すると、常にログインページとしてルートビューコントローラーに移動します。

//for home tab..


    UINavigationController *nav1 = [[UINavigationController alloc] init];

    UIViewController *viewController1;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        viewController1 = [[[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil] autorelease];
    } else
    {
        viewController1 = [[[LoginViewController alloc] initWithNibName:@"LoginViewController_iPad" bundle:nil] autorelease];
    }

    nav1.viewControllers = [NSArray arrayWithObjects:viewController1, nil];



    //for account tab...
    UINavigationController *nav2 = [[UINavigationController alloc] init];
    UIViewController *viewController2;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        viewController2 = [[[AccountView alloc] initWithNibName:@"AccountView_iPhone" bundle:nil] autorelease];
    } else
    {
        viewController2 = [[[AccountView alloc] initWithNibName:@"AccountView_iPad" bundle:nil] autorelease];
    }
    nav2.viewControllers = [NSArray arrayWithObjects:viewController2, nil];

    //for links tab...
    UINavigationController *nav3 = [[UINavigationController alloc] init];
    UIViewController *viewController3;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        viewController3 = [[[LinksView alloc] initWithNibName:@"LinksView_iPhone" bundle:nil] autorelease];
    } else
    {
        viewController3 = [[[LinksView alloc] initWithNibName:@"LinksView_iPad" bundle:nil] autorelease];
    }
    nav3.viewControllers = [NSArray arrayWithObjects:viewController3, nil];

    //for about us tab...
    UINavigationController *nav4 = [[UINavigationController alloc] init];
    UIViewController *viewController4;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        viewController4 = [[[AboutUsView alloc] initWithNibName:@"AboutUsView_iPhone" bundle:nil] autorelease];
    } else
    {
        viewController4 = [[[AboutUsView alloc] initWithNibName:@"AboutUsView_iPad" bundle:nil] autorelease];
    }
    nav4.viewControllers = [NSArray arrayWithObjects:viewController4, nil];


    self.tabBarController = [[[UITabBarController alloc] init] autorelease];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nil];

    self.tabBarController.tabBar.tintColor = [UIColor blackColor];

    //self.tabBarController.tabBar.tintColor = [UIColor colorWithRed:237.0/255.0 green:208.0/255.0 blue:0.0/255.0 alpha:1.0];

    self.window.rootViewController=self.tabBarController;

どうすればこれを解決できますか?

4

3 に答える 3

0

以下のようにviewController mtoを割り当てるだけUINavigationControllerです。

UINavigationController *nav1 =[[UINavigationController alloc]initWithRootViewController:viewController1];

UINavigationController *nav2 =[[UINavigationController alloc]initWithRootViewController:viewController2];

UINavigationController *nav3 =[[UINavigationController alloc]initWithRootViewController:viewController3];

UINavigationController *nav4 =[[UINavigationController alloc]initWithRootViewController:viewController4];

次に、コードと同じようにタブバーに割り当てます..

self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nil];
self.window.rootViewController = self.tabBarController;
于 2012-12-12T09:35:31.367 に答える
0

tabBarControllerなしで Loginview を表示するには、別の方法を使用する必要があります。 tabBarController
で LoginView を使用しないでください。login のようなブール値を選択する必要があります。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSUserDefaults *default=[NSUserDefaults standardUserDefaults];
if(![default boolForKey:@"login"])
{
    //here tab is your tabBarController.
    [tab presentViewController:yourLoginView animated:YES completion:nil];
}
else{
    //your normal code
}

ユーザー ログイン後、login=YES を設定できます。

于 2013-07-12T10:55:40.597 に答える
0

このソリューションを見てください。基本的に、ユーザーがログインした後に をから に
切り替えることができます。しかし、あなたの「最初のページ」ではなく、独立したviewControllerである必要があると思います。rootViewControllerloginVCtabBarVCloginVCtabBarVC

ただし、とにかく最初のタブでログインしたい場合は、ユーザーがログインした後に VC のビューを変更するだけです。NSUserDefaults
に フラグを設定して、ユーザーがログインしているかどうかを知ることができるので、最初のタブでユーザーがログインしているかどうかを確認し、別の UI を表示できます。viewDidAppear:

追伸: iPhone/iPad 用の別の xib をロードするすべての条件をここに書かないようにするためのちょっとしたトリックを見つけることができます。

于 2012-12-12T11:56:41.453 に答える