IOS TabBarController问题

时间:2011-10-24 04:23:35

标签: uitabbarcontroller ios5 uitabbaritem

TabBar将是2个问题。我正在使用TabBar和NavigationController的组合。如下链接。

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CombiningViewControllers/CombiningViewControllers.html

问题1:

我想在TabBar之前出现到另一个ViewController。这里有几个检查。 (例如,Facebook登录)如果满足先决条件,将显示标签栏。我该怎么办?

问题2:

TabBar屏幕图标显示在第一个TabBar的中间。以下代码序列也会影响TabBarItem的顺序。

self.tabBarController.viewControllers = [NSArray arrayWithObjects: viewController1, viewController2, nil];

谢谢。

Okan Sahin

1 个答案:

答案 0 :(得分:1)

对于那些有同样问题的人:

我正在使用Xcode 4.2。我创建了Tabbed App。

回答1:

用于加载屏幕,

我创建了一个新的ViewController。

AppDelegate.m

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

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    UIViewController *viewControllerLoading = [[LoadingViewController alloc] initWithNibName:@"LoadingViewController" bundle:nil];

    self.window.rootViewController = viewControllerLoading;

    [self.window makeKeyAndVisible];

    return YES;
}

LoadingViewController.h

@interface LoadingViewController : UIViewController <UITabBarControllerDelegate>

@property (strong, nonatomic) UITabBarController *tabBarController;

@end

LoadingViewController.m

 UIViewController *viewControllerFriends = [[FriendsViewController alloc] initWithNibName:@"FriendsViewController" bundle:nil];
    UINavigationController* navController1 = [[UINavigationController alloc]
                                              initWithRootViewController:viewControllerFriends];
    UIViewController *viewConrollerMessages = [[MessagesViewController alloc] initWithNibName:@"MessagesViewController" bundle:nil];
    UINavigationController* navController2 = [[UINavigationController alloc]
                                              initWithRootViewController:viewConrollerMessages];
    UIViewController *viewControllerWorld = [[WorldViewController alloc] initWithNibName:@"WorldViewController" bundle:nil];
    UINavigationController* navController3 = [[UINavigationController alloc]
                                              initWithRootViewController:viewControllerWorld];

    UIViewController *viewControllerCheckIn = [[CheckInViewController alloc] initWithNibName:@"CheckinViewController" bundle:nil];
    UINavigationController* navController4 = [[UINavigationController alloc]
                                              initWithRootViewController:viewControllerCheckIn];

    UIViewController *viewControllerProfile = [[ProfileViewController alloc] initWithNibName:@"ProfileViewController" bundle:nil];
    UINavigationController* navController5 = [[UINavigationController alloc]
                                              initWithRootViewController:viewControllerProfile];

    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController1, navController2, navController3, navController4, navController5, nil];

    [self.view addSubview:self.tabBarController.view];

回答2:

    self.tabBarController.selectedIndex = 2;

祝你好运

Okan Sahin