Simplified iOS

  • Home
  • About
  • Contact
  • Advertise
  • Write for Us

iOS UINavigationController Tutorial – Displaying Multiple Screens

October 27, 2016 by Belal Khan 1 Comment

Till now in all our examples we used only a single view screen. But any application contains many screens with a hierarchy. Like a user will see Login Screen first and then after Login user will see the profile screen. For handling multiple screens in the Storyboard we have iOS UINavigationController.

UINavigationController manages all the screens of the app. It uses a navigation stack, the bottom of the stack contains the root view and at the top we have the screen that is currently displaying. To switch between the screens we can use the push and pop method. So in this iOS UINavigationController Tutorial we will see a simple example using Swift.

iOS UINavigationController Tutorial

Creating UINavigationController

  • First we will create a new iOS Single View Application.

ios uinavigationcontroller

  • Now come inside Main.storyboard.
  • Make sure your the ViewController is selected then go to Editor -> Embed In -> Navigation Controller.

ios uinavigationctonroller

  • Now your Storyboard will look like this.

ios navigationcontroller

  • So we have the first screen of the app. And we have given title as also First Screen.

Creating Another View Controller

  • As we want to deal with multiple screens. So we will create another View Controller. So drag View Controller to Storyboard.

ios uinavigationcontroller

  • Now we will create a swift class for this View Controller.
  • On the Bottom Left Corner you will see a + Sign click there and select File.

ios uinavigationcontroller tutorial

  • Now select Swift File and click next.

ios uinavigationcontroller

  • Now you will asked to give name of the file. I just given the name SecondViewController.swift.

ios navigationcontroller

  • Now open the file SecondViewController.swift and write the following code in it.
//
//  SecondViewController.swift
//  NavigationControllerExample
//
//  Created by Belal Khan on 27/10/16.
//  Copyright © 2016 Belal Khan. All rights reserved.
//

import UIKit

class SecondViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
}
  • Now we need to add this class for our Second View Controller that we already created. So come inside Storyboard and select the Second View Controller.

ios navigationcontroller

  • So we have defined the class SecondViewController.swift that we just created for this View Controller.
  • Now we have two View Controllers.

Switching Between Views

  • To switch between Views we need something, in this case we will create a Button in First View Controller. And when the button is clicked we will open the Second View Controller.
  • So drag a button inside the First View Controller.

uinavigationcontroller

  • Now press Control and Drag this Button to your Second View Controller.

ios uinavigationcontroller

  • Now you will see a small popup, select push from the options.

ios navigationviewcontroller

  • And now your both View Controllers are connected.

ios uiviewcontroller

  • I also added a title to Second View Controller, same as we did with the First View Controller.
  • You can also add a button to the Second View Controller and repeat the same process to come back to First View Controller from Second View Controller. (Though this is not necessary because we will get this option by default in the Title Bar of the View Controller).

ios uiviewcontroller

  • Now just run the application in Simulator.

ios uiviewcontroller

  • So it is working absolutely fine.

Thats all for this iOS UINavigationController Tutorial friends. In next tutorial we will learn how to create User Registration and Login Options in our iOS Application using MySQL Database and PHP. And don’t hesitate to leave you comments if you are having some confusions regarding this iOS UINavigationController Tutorial. Thank You 🙂

Share this:

  • Tweet
  • Share on Tumblr
  • WhatsApp

Related

Filed Under: iOS Development Tutorial Tagged With: ios uinavigationcontroller, storyboard navigation controller, uinavigationcontroller

About Belal Khan

I am Belal Khan, I am currently pursuing my MCA. In this blog I write tutorials and articles related to coding, app development, iphone etc.

Comments

  1. joe chen says

    November 18, 2017 at 7:53 pm

    damn good tutorial! thanks man!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *




About Me

belal khan simplified ios

Hello I am Belal Khan, founder and owner of Simplified iOS. I am currently pursuing MCA from St. Xavier's College, Ranchi. Apart from my academic I am a blogger, I run various websites and majority of them are about coding and development.

Connect with Me

Follow Simplified iOS

Simplified iOS

Popular Posts

  • Swift PHP MySQL Tutorial – Connecting iOS App… (94,532)
  • Swift SQLite Tutorial for Beginners – Using… (94,175)
  • UIWebView Example to Load URL in iOS using Swift in Xcode (78,244)
  • Xcode Login Screen Example using Swift 3, PHP and MySQL (65,225)
  • Download Full High Sierra Installer to Create Bootable USB (61,246)
  • How to Format USB on Mac? Formatting External Hard… (60,779)
  • Swift JSON Tutorial – Fetching and Parsing… (58,674)
  • Firebase Realtime Database Tutorial for Swift using Xcode (52,001)
  • iOS Registration Form Example using PHP and MySQL (46,976)
  • Xcode Text Field Tutorial for iOS Application using Swift (39,039)




About

Simplified iOS is a blog where you can find latest tutorials related to coding and app development for iphone and MAC OS. Here you can get Simplified iPhone, iPad and Mac OS development tutorial to know the things about Apple Development from basics to advanced level.

Quick Links

  • Advertise
  • Contact
  • Disclaimer
  • Privacy Policy
  • Write for Us

Copyright © 2017 · Simplified iOS· All rights Reserved. And Our Sitemap.All Logos & Trademark Belongs To Their Respective Owners·