0

我是IOS应用开发学习的初学者。我有一个登录屏幕作为我的第一个视图控制器,我需要第二个视图控制器作为选项卡栏视图控制器。有 4 个不同的选项卡,我有 4 个不同的 XIB 供它们使用。

有人帮助我继续前进。

4

4 回答 4

2

最好的方法是在应用程序从标签栏控制器的第一个屏幕启动时以模态方式显示登录屏幕,在 viewWillAppear 中添加用于显示登录屏幕的代码,并在登录后关闭屏幕。您可以像这样在 appDelegate 中创建 TabBarController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{


    UITabBarController tabBarController=[[UITabBarController alloc] init]; 


    FirstViewController *firstVC =  [[UIViewController alloc] initWithNibName:@"FirstVC" bundle:nil];
    UINavigationController *firstNavController = [[UINavigationController alloc] initWithRootViewController: firstVC];     

    SecondViewController *secondVC = [[UIViewController alloc] initWithNibName:@"secondVC" bundle:nil];
    UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:secondVC]; 

   tabBarController.viewControllers = [NSArray arrayWithObjects: firstNavController, secondNavController, nil];

    tabBarController.selectedIndex=0;
    tabBarController.delegate = self;

UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:@"Movies" image:[UIImage imageNamed:@"MoviesTAB.png"] tag:1];

    [firstVC  setTabBarItem:item1];

    UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:@"Music" image:[UIImage imageNamed:@"musicTAB.png"] tag:2];
    [seconfVC setTabBarItem:item2];

    tabController.tabBar.translucent  = NO;
    tabController.tabBar.barStyle = UIBarStyleBlack;
    tabBarController.tintColor = [UIColor whiteColor];

    self.window.rootViewController = tabController;
return YES;
}
于 2013-11-12T10:30:38.847 回答
0

最好的方法是使用情节提要,并且只有一个初始 UIViewController,然后从它转到 UITabBarViewController。 http://youtu.be/a_DCTSTv1Mw

于 2013-11-12T10:17:06.940 回答
0

如果你想通过 xib 制作一个 UITabBarViewController 并将 viewControllers 添加到该 UITabBarViewController 对象的对象数组中。

示例代码:

    NSMutableArray *arrViewControllers = [[NSMutableArray alloc] init];

    UIViewController *tabController;
    UIImage *tabImage ;
    NSString *tabTitle;

    for (int i= 0; i < 3; i++) {
        switch (i) {
            case 0:
                tabController = [[ViewController alloc] init];
                tabImage = [UIImage imageNamed:@"icon1.png"];
                tabTitle = @"Text";
                break;

            case 1:
                tabController = [[ImageDemoViewController alloc] init];
                tabImage = [UIImage imageNamed:@"icon2.png"];
                tabTitle = @"Image";
                break;
            case 2:
                tabController = [[TableDemoViewController alloc] init];
                tabImage = [UIImage imageNamed:@"icon3.png"];
                tabTitle = @"Table";
                break;
        }
        // set the image and title using some properties of UIViewController

        tabController.tabBarItem.image = tabImage;
        tabController.tabBarItem.title = tabTitle;

        //add objects to array

        [arrViewControllers addObject:tabController];

        [tabController release];
    }

    _baseController = [[UITabBarController alloc] init];
    _baseController.viewControllers =  arrViewControllers;

    [arrViewControllers release];
于 2013-11-12T10:18:24.510 回答
0

去你的 appDelegate

1.为登录屏幕创建一个viewController。

LoginViewController *viewController1 = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];

2.create a navigationController 与您的登录 ViewController 的根视图。

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

3.将navigationController设为窗口的根视图。

self.window.rootViewController = self.nVC;
    [self.window makeKeyAndVisible];

现在转到 LoginViewController 中登录按钮的 Touch-Up-Inside 方法。

1.验证密码和用户 ID 后,为 tabbar 和 TabbarViewController 初始化 viewController。

UiViewController ...*yourViewControllers,..,
UITabBarController *YourtabBarController = [[UITabBarController alloc] init];

2.现在将这些 viewControllers 添加到您的 tabbarController。

 YourtabBarController.viewControllers = @[  YourViewController1,YourViewController2,YourViewController3,......];

3.最后将这个tabbarController推送到navigationControllere。

[self.navigationController pushViewController:YourtabBarController animated:NO];
于 2013-11-12T11:11:28.920 回答