presentViewController and displaying navigation bar

后端 未结 12 468
自闭症患者
自闭症患者 2020-12-07 13:27

I have a view controller hierarchy and the top-most controller is displayed as a modal and would like to know how to display the navigation bar when using

\         


        
相关标签:
12条回答
  • 2020-12-07 14:24

    I had the same problem on ios7. I called it in selector and it worked on both ios7 and ios8.

    [self performSelector: @selector(showMainView) withObject: nil afterDelay: 0.0];
    
    - (void) showMainView {
        HomeViewController * homeview = [
            [HomeViewController alloc] initWithNibName: @
            "HomeViewController"
            bundle: nil];
        UINavigationController * navcont = [
            [UINavigationController alloc] initWithRootViewController: homeview];
        navcont.navigationBar.tintColor = [UIColor whiteColor];
        navcont.navigationBar.barTintColor = App_Theme_Color;
        [navcont.navigationBar
        setTitleTextAttributes: @ {
            NSForegroundColorAttributeName: [UIColor whiteColor]
        }];
        navcont.modalPresentationStyle = UIModalPresentationFullScreen;
        navcont.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self.navigationController presentViewController: navcont animated: YES completion: ^ {
    
        }];
    }
    
    0 讨论(0)
  • 2020-12-07 14:27

    One solution

    DetailViewController *controller = [[DetailViewController alloc] initWithNibName:nil                                                                                 
                                            bundle:[NSBundle mainBundle]];  
    
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
    navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    navController.modalPresentationStyle = UIModalPresentationCurrentContext;
    
    
    
    [self.navigationController presentViewController:navController 
                                            animated:YES 
                                            completion:nil];
    
    0 讨论(0)
  • 2020-12-07 14:29

    Can you use:

    [self.navigationController pushViewController:controller animated:YES];
    

    Going back (I think):

    [self.navigationController popToRootViewControllerAnimated:YES];
    
    0 讨论(0)
  • 2020-12-07 14:29

    I use this code. It's working fine in iOS 8.

    MyProfileEditViewController *myprofileEdit=[self.storyboard instantiateViewControllerWithIdentifier:@"myprofileeditSid"];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myprofileEdit];
    [self presentViewController:navigationController animated:YES completion:^{}];
    
    0 讨论(0)
  • 2020-12-07 14:31

    It is true that if you present a view controller modally on the iPhone, it will always be presented full screen no matter how you present it on the top view controller of a navigation controller or any other way around. But you can always show the navigation bar with the following workaround way:

    Rather than presenting that view controller modally present a navigation controller modally with its root view controller set as the view controller you want:

    MyViewController *myViewController = [[MyViewController alloc] initWithNibName:nil bundle:nil];
    UINavigationController *navigationController = 
        [[UINavigationController alloc] initWithRootViewController:myViewController];
    
    //now present this navigation controller modally 
    [self presentViewController:navigationController
                       animated:YES
                       completion:^{
    
                            }];
    

    You should see a navigation bar when your view is presented modally.

    0 讨论(0)
  • 2020-12-07 14:31

    If you use NavigationController in Swift 2.x

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let targetViewController = storyboard.instantiateViewControllerWithIdentifier("targetViewControllerID") as? TargetViewController
    self.navigationController?.pushViewController(targetViewController!, animated: true)
    
    0 讨论(0)
提交回复
热议问题