In the previous tutorial Using UINavigationController component into your iOS App Part One we saw how easy is to develop application with multiple UIViewController-s using Storyboard and UINavigationController as navigation mechanism. With only few click we can connect all relations and easy we can implement simple fully functional prototype for presentation which can be exported, distributed and installed on device.

In this part, part two we will see other approach of using UINavigationController but this time with manually initialization in the application AppDelegate and navigating between view controllers manually pushing view controllers to navigation stack. Some of the developers prefer previous approach and some this approach, sometimes its matter of choice and sometimes its depends on the project.

Let’s start.


We are starting with creating the Single View Application in our Xcode IDE.

Screen Shot 2016-07-11 at 11.09.50


Next we are setting Product Name, Organisation Name, Identifier, Language ( Objective-C or Swift ) and Device.

Screen Shot 2016-08-15 at 00.24.50


Your project should look like this after finishing previous step:

Screen Shot 2016-08-15 at 00.25.38


Because in this tutorial we will not use views and view controllers from the storyboard first we need to create one view for our existing UIViewController.

Screen Shot 2016-08-15 at 00.26.19


We are selecting from the menu iOS / User Interface and then we are selecting View icon.

Screen Shot 2016-08-15 at 00.26.30



Screen Shot 2016-08-15 at 00.27.14


For our new created view we are setting the size and we are choosing compact, portrait for all iPhones.

Screen Shot 2016-08-15 at 00.27.20


Next we are selecting File’s Owner and in Identity Inspector for Class we are selecting ViewController, the class where the whole logic connected with this view will be written.

Screen Shot 2016-08-15 at 00.28.19


From Object Library we are dropping to the view two buttons same like in the previous example from tutorial Using UINavigationController component into your iOS App Part One and we are making small customization on default buttons with setting background colors etc.

Screen Shot 2016-08-15 at 00.36.23


For buttons we are creating action methods by dragging from the Interface Builder over Assistant Editor.

Screen Shot 2016-08-15 at 00.36.53


Screen Shot 2016-08-15 at 00.37.09

Screen Shot 2016-08-15 at 00.37.48

Screen Shot 2016-08-15 at 00.38.24


We must associate View from Interface Builder with View Outlet in Connection Inspector otherwise the view from the xib file will not be connected with view from view controller and the application will crash with exception.

Screen Shot 2016-08-15 at 01.00.01


In applications AppDelegate first we are adding class property for UINavigationController, then in the first method, didFinishLaunchWithOptions, we are making instance from our first view controller. After that we are making initialization of class property of uiNavigationController and as rootViewController we are setting the instance of our first view controller so this will be the first view what we will see after starting the application. When we finish we initialization next we are initializing window class property and for rootViewController we  are setting the instance of UINavigationController, uiNavigationController.

Screen Shot 2016-08-15 at 00.45.39


For our example we must create two more UIViewController-s so in the menu we are selecting New File.

Screen Shot 2016-08-15 at 01.02.50


We are choosing type of source file, Cocoa Touch Class.

Screen Shot 2016-08-15 at 01.02.57


On the next window we are checking the checkbox, Also create XIB file.

Screen Shot 2016-08-15 at 01.03.09


After creating the second view controller we are continuing with creating third view controller. When we finish our project should look like on the image bellow.

Screen Shot 2016-08-15 at 01.04.07


For new created xib files first we must select size of the view to match for all iPhones and then we are changing the background color to match the color on the buttons. Its good to mention that for new created view controllers that come with created xib files we dont need to set File’s Owner Class name and to make connection from the view to the view from the controller because when we created this view controllers with corresponding xib files they were automatically connected.

Screen Shot 2016-08-15 at 01.05.42


Screen Shot 2016-08-15 at 01.05.53


In first view controller class in method viewDidLoad we are setting manually the property title an that we are doing the same for the second and third view controller.

IScreen Shot 2016-08-15 at 01.11.24


In action methods we are making instance from new created view controllers we corresponding xib file names and then we are calling the method which came from the UINavigationController, .pushViewController where we pass the instance of the previously instantiated view controllers.

Screen Shot 2016-08-15 at 01.11.47


When we compile and run the application in the simulator we can press buttons so we can see if everything we have implemented correctly how its working.

Screen Shot 2016-08-15 at 01.15.39 Screen Shot 2016-08-15 at 01.16.06 Screen Shot 2016-08-15 at 01.16.25


Complete source code can be found on my GitHub ready for testing.

Print Friendly, PDF & Email

Leave a Comment

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