views:

112

answers:

2

I have a UITabBarControllerDelegate that pushes a new view controller when a certain tab is pressed:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    MyView* myView = [[[MyView alloc] initWithNibName:@"MyView" bundle:nil]autorelease];
        if([self.tabBarController.selectedViewController.title isEqualToString:@"Friends"]){
        NSLog(@"Clicked Friends");
        myView.reloadFriends = TRUE;
        [self.navigationController myView animated:YES]; 
    }
}

However, if I change my code to set the tabbar's selected view controller to myView everything works, but I don't get my navigation bar:

if([self.tabBarController.selectedViewController.title isEqualToString:@"Friends"]){
        NSLog(@"Clicked Friends");
        myView.reloadFriends = TRUE;
        self.tabBarController.selectedViewController = myView; 
}

How can I set the reloadFriends property in MyView and have the navigation bar at the top?

EDIT: I have also tried the following code w/ no luck:

[self.tabBarController.selectedViewController.navigationController pushViewController:myView animated:YES];
A: 

I have personally stuck to the style of maintaining my own reference to the navigation controller in the app delegate, and I use the app delegate's reference to the navigation controller to push the new view.

sylvanaar
i don't think i am understanding you. could you post some code to help me understand?
Sheehan Alam
A: 

Solved:

if ([viewController isKindOfClass:[UINavigationController class]])
{
            [(UINavigationController *)viewController pushViewController:myView animated:NO];
}
Sheehan Alam