pushViewController without navigationcontroller

前端 未结 5 1468
执念已碎
执念已碎 2020-12-31 06:54

I have a class that is of type UITableViewController. This class has a member of type UINavigationBar that I use for adding in an edit button for t

相关标签:
5条回答
  • 2020-12-31 07:15

    You can't push a view controller onto a navigation controller if there is no navigation controller. If you are wanting to be pushing controllers and have it display the topmost controller and everything, just use a UINavigationController and be done with it.

    You can push arbitrary UINavigationItems onto your UINavigationBar, and your bar's delegate will be notified when the user uses the back button so you can take appropriate action. See the documentation for more information.

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

    It's true that without a UINavigationController you can not push view controllers. You rather present view controllers modally via UIViewController.present(_ viewControllerToPresent:, animated:, completion:)

    But it's possible to create a custom segue to display the view controller as if it were a push (or any other animation you want), although it seems that using a UINavigationController just makes things easier.

    Here are some related links to the documentation:

    UINavigationController Class Reference

    Customizing the Transition Animations

    Presenting a Modal View Controller

    0 讨论(0)
  • I would wrap the UITableView inside a UINavigationController and just hide the UINavigationBar.

    [self.navigationController setNavigationBarHidden:YES animated:NO];
    

    And then create a back button that pops the ViewController off the stack.

    [self.navigationController popViewControllerAnimated:YES]
    
    0 讨论(0)
  • 2020-12-31 07:24

    The closest alternative if you don't want to use navigation controller are modal view controllers.

    [self presentViewController:controller animated:YES completion:nil];
    

    This will slide the controller into your screen from bottom, or if you change controller's modalTransitionStyle it can flip over or fade in.

    To dismiss the controller just call:

    [self dismissViewControllerAnimated:YES completion:nil];
    
    0 讨论(0)
  • 2020-12-31 07:29

    What could also be done is to use a Navigation Controller as usual and then hide it.

    To hide the Navigation Controller using storyboards: select it and uncheck "Show Navigation Bar" in the attribute inspector. Others might suggest to hide the navigation bar in each controller, but the problem with that is that it will appear for a millisecond and then disappear.

    Navigation Controller attributes tab

    0 讨论(0)
提交回复
热议问题