Search code examples
iphonexcodefacebook-ios-sdkios6

Integration with Facebook Initial ViewController has a UITabBarController instead of UINavigationController


The title pretty much says it all. I'm trying to create an interface where after connecting with Facebook, the window loads up my HomeViewController (my initially selected UITabBarItem). Although, I do not want the UINavigationBar that comes through as I have set the HomeViewController as the LoginViewController's root view. I have different navigation bar items for each view, so defaulting to that one won't work. I have this code now.

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.mainViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.mainViewController];
    self.window.rootViewController = self.navigationController;
}

Solution

  • After a good nights sleep, I was able to figure it out. Hopefully, this can help others out there!

    AppDelegate.m

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.tabBarController = [[UITabBarController alloc] init];
    
        // Initialize view controllers
        HomeViewController *homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
        ConnectViewController *connectViewController = [[ConnectViewController alloc] initWithNibName:@"ConnectViewController" bundle:nil];
        PartyControlViewController *partyControlViewController = [[PartyControlViewController alloc] initWithNibName:@"PartyControlViewController" bundle:nil];
        MeViewController *meViewController = [[MeViewController alloc] initWithNibName:@"MeViewController" bundle:nil];
        MoreViewController *moreViewController = [[MoreViewController alloc] initWithNibName:@"MoreViewController" bundle:nil];
    
        [self.tabBarController setViewControllers:[NSArray arrayWithObjects:homeViewController, connectViewController, partyControlViewController, meViewController, moreViewController, nil]];
    
        // Customize Tab Bar
        UITabBarItem *homeTab = [[UITabBarItem alloc] initWithTitle:@"Home" image:nil tag:0];
        UITabBarItem *connectTab = [[UITabBarItem alloc] initWithTitle:@"Connect" image:nil tag:1];
        UITabBarItem *partyControlTab = [[UITabBarItem alloc] initWithTitle:@"Party Control" image:nil tag:2];
        UITabBarItem *meTab = [[UITabBarItem alloc] initWithTitle:@"Me" image:[UIImage imageNamed:@"person.png"] tag:3];
        UITabBarItem *moreTab = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMore tag:4];
    
        [homeViewController setTabBarItem:homeTab];
        [connectViewController setTabBarItem:connectTab];
        [partyControlViewController setTabBarItem:partyControlTab];
        [meViewController setTabBarItem:meTab];
        [moreViewController setTabBarItem:moreTab];
    
        self.window.rootViewController = self.tabBarController;
    }