简体   繁体   中英

iOS app navigation, best practices using Swift

I'm new to iOS development, and I would like to understand what are best practices in creating navigation between View Controllers.

Example:

  1. Suppose I have View controllers V1, V2, V3

  2. at the bottom of view controllers I have menu navigation like Button1, Button2, Button3 Each button should be linked to V1, V2, V3 controllers accordingly

  3. In V1 controller I need to create following action methods in order to connect button2 and button3 with views:

     @IBAction func clickOnButton2(sender : AnyObject) { let v2 = self.storyboard.instantiateViewControllerWithIdentifier("v2") as V2ViewClass self.navigationController.pushViewController(v2, animated: true) } @IBAction func clickOnButton3(sender : AnyObject) { let v3 = self.storyboard.instantiateViewControllerWithIdentifier("v3") as V3ViewClass self.navigationController.pushViewController(v3, animated: true) } 

Since navigation menu is the same in all view controllers, is there a way I can create navigation class to reuse it in each view ? Or I need to create redundant button actions for each view controller?

Thank you!

You should probably be using a UITabBarViewController .

Then you can setup all of this navigation directly in your storyboard. You can drag a UITabBarController onto the canvas from the Object library and then connect that to each of the view controllers you would like to navigate between by right click dragging to the view controller on the canvas and selecting view controllers . A new tab will be added for each view controller you connect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM