开发者

UINavigationController does not set view properties correctly when pushed

I have a UITabBarContr开发者_运维问答ollerDelegate 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];


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.


Solved:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜