pa12
pa12

Reputation: 1503

loading Tabbar controller from view controller

I am working with a project in which I have to have a login page and after successful login we should have a tabbar view (I am using tab bar controller) when I try to load the tab bar controller using the following code.Nothing works out.

LoginSuccess *viewController = [[LoginSuccess alloc] initWithNibName:@"LoginSuccess" bundle:nil];
        [self.view addSubview:viewController.tabBarController.view];
        [viewController release];

please help me.

Upvotes: 0

Views: 1093

Answers (1)

GhostRider
GhostRider

Reputation: 1207

I do same work but me call appdelegate after success of login response [mAppDelegate loadTabbar];//call function in delegate file to load tabbar view whom code is follow

#pragma mark -
#pragma mark Load TabBar
-(void)loadTabBar
{
    self.tabBarController = [[UITabBarController alloc] init];
    tabBarController.delegate = self;

    MyAlarmVC *myAlarmVC = [[MyAlarmVC alloc] initWithNibName:@"MyAlarmVC" bundle:nil];
    UINavigationController *myAlarmNVC = [[UINavigationController alloc] initWithRootViewController:myAlarmVC];
    myAlarmNVC.navigationBar.tintColor = [UIColor whiteColor];
    [myAlarmVC release];


    MyVideosVC *myVideoVC = [[MyVideosVC alloc] initWithNibName:@"MyVideosVC" bundle:nil];
    UINavigationController *myVideoNVC = [[UINavigationController alloc] initWithRootViewController:myVideoVC];
    myVideoNVC.navigationBar.tintColor = [UIColor whiteColor];
    [myVideoVC release];


    MyFriendsVC *myFriendVC = [[MyFriendsVC alloc] initWithNibName:@"MyFriendsVC" bundle:nil];
    UINavigationController *myFriendNVC = [[UINavigationController alloc] initWithRootViewController:myFriendVC];
    myFriendNVC.navigationBar.tintColor = [UIColor whiteColor];
    [myFriendVC release];


    MyMessageVC *myMessageVC = [[MyMessageVC alloc] initWithNibName:@"MyMessageVC" bundle:nil];
    UINavigationController *myMessageNVC = [[UINavigationController alloc] initWithRootViewController:myMessageVC];
    myMessageNVC.navigationBar.tintColor = [UIColor whiteColor];
    [myMessageVC release];

    MyProfileVC *myProfileVC = [[MyProfileVC alloc] initWithNibName:@"MyProfileVC" bundle:nil];
    UINavigationController *myProfileNVC = [[UINavigationController alloc] initWithRootViewController:myProfileVC];
    myProfileNVC.navigationBar.tintColor = [UIColor whiteColor];
    [myProfileVC release];

    tabBarController.viewControllers = [NSArray arrayWithObjects:myAlarmNVC,myVideoNVC, myFriendNVC,myMessageNVC,myProfileNVC, nil];
    [myAlarmNVC release];
    [myVideoNVC release];
    [myProfileNVC release];
    [myFriendNVC release];
    [myMessageNVC release];
    [self.window addSubview:tabBarController.view ];
    //tabBarController.navigationController.navigationBarHidden = YES;
    [self.tabBarController release];

}

- (void)tabBarController:(UITabBarController *)tabBarController1 didSelectViewController:(UIViewController *)viewController{

    NSArray *vc= tabBarController1.viewControllers;

    for (int i = 0; i < [vc count]; i++) {

        UINavigationController *nc = [vc objectAtIndex:i];

        if (nc == tabBarController1.selectedViewController) {

            continue;
        }

[nc popToRootViewControllerAnimated:NO];
    }

}

if you got problem then just tell me the view names of your tabbar

Upvotes: 1

Related Questions