How does a Navigation-based application get access to the UINavigationController class? - objective-c

In a Navigation-based application, the method pushViewController:animated can be used. This is a method of the UINavigationController class. However, nowhere in the source files do I see any #import statements that import this class. The documentation doesn't show UIViewController as inheriting from UINavigationController.
So how are Navigation-based applications able to access this method?

UIViewController has a property called navigationController which is an instance of a UINavigationController. This is how it gets access to it.

Related

What's the difference between UIViewController and ViewController?

I just noticed after adding a new ViewController that it isn't a UIViewController like the one created by Xcode. I didn't find an answer on google so I hope one of you could explain the difference between these two to me.
Edit
To clarify my question:
This is the declaration of my UIViewController:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
And this is the declaration of my ViewController:
#import "ViewController.h"
#interface GameViewController : ViewController
What is the difference between these two ViewControllers?
What is the difference between these two ViewControllers?
Not a great deal, but it depends on the functionality defined in ViewController. It's fairly common to create a base class that contains common functionality you want in all derived classes, and view controller classes are no exception here.
However if ViewController contains no real functionality, then you can simply remove it and derive GameViewController directly from UIViewController:
#import <UIKit/UIKit.h>
#interface GameViewController : UIViewController
I would be very surprised if Xcode generated both ViewController and GameViewController in one operation, as you imply in your question, however. If it did, then that's new to me and I cannot see why it did it.
UIViewController provides infrastructure of the view, and when you make your own ViewController it is inherited from UIViewController. Just to be clear: you do not modify UIViewController, you subclass it, and then modify by your own.
UIViewController is a class provided by Apple. In order to perform UI customization for your app, you usually create subclasses of UIViewController.
ViewController is an example subclass of UIViewController.
A View Controller is a concept, is what manages a part of your user interface and interaction.
Based on the documentation:
View controllers are the foundation of your app’s internal structure. Every app has at least one view controller, and most apps have several. Each view controller manages a portion of your app’s user interface as well as the interactions between that interface and the underlying data. View controllers also facilitate transitions between different parts of your user interface.
An UIViewController is just the base class of this already defined "View Controller", you add a viewController as you said, but a viewController has a class associated to it, that can be a UIViewController, UITableViewController, or variations/subclasses.

Xcode storyboard outlet for navigation controller

I am trying to implement what I found in this tutorial myself, so I downloaded the project used in the tutorial from github (here)
The project has a storyboard with three ViewControllers: a navigation controller, the root view controller and a third ViewController. There is a push segue between the root ViewController and the third ViewController, the purpose of the tutorial is creating a custom transition animation.
The NavigationController is set as an outlet property in the NavigationControllerDelegate class:
#property (weak, nonatomic) IBOutlet UINavigationController *navigationController;
Also, the delegate of the navigationController is also set to the NavigationControllerDelegate class.
My question is how was this achieved using IB and Xcode?
In my project I tried pulling an outlet from the storyboard to a property in my own NavigationControllerDelegate class without success. And I also can't find a way to set the delegate of the NavigationController to my NavigationControllerDelegate class using the Xcode interface.
Here's a print screen of how that looks in the project:
Can someone please explain how this can be done using the Xcode gui?

Using a custom UITableViewController class in Storyboard

In my storyboard, I have created a new UITableViewController object for which I would like to specify some custom code. I created a new controller with the following header:
#interface CustomController : UITableViewController
When I select the UITableViewController in the Storyboard view and navigate to the Identity Inspector, I can see my CustomController in the Custom Class drop-down. However, when I select it, I hear an error sound, which is referred to as "Morse" in the system preferences.
When I deselect the UITableViewController and re-select it, it has cleared my CustomController selection and replaced it with UITableViewController. I do not understand why XCode does not accept this, as from my understanding, this is all that is required to add your own code to a UITableViewController. I am not sure if I have encountered an XCode bug or if I have configured my class incorrectly.
It is possible to use a UIViewController as a UITableViewController, but you have to do some work. If you "convert" a UIViewController to a UITableViewController, you'll need to implement the UITableViewDelegate and UITableViewDatasource protocols. You may also need to provide an outlet for a UITableView. You'll also need to handle keyboard events. Basically a bunch of effort for not much return.
Probably best in your case to start fresh with a new UIViewController class inheritted from UITableViewController.

Objective C - Accessing UINavigationController from TabController application

How can I access the UINavigationController from the AppDelegate class in a UITabBarController application?
Like when I'm in a section within the UITabBarController item, I can do self.navigationController.
However, that doesn't exist in the AppDelegate.
Thank you,
Tee
There's no correspondence between navigation controller and app delegate the way there is between navigation controller and the view controllers under it. If your app delegate sets up the navigation controller for a given tab item, it can certainly keep a reference to it in a property or ivar, but you'll need to manage that yourself.

Mapkit View with tableview together

I am new to Iphone Dev, seems doesn't really understand delegate things. Could we put mapkit view and tableview together in one view?
I searched over, and someone said we can't use more than one delegate in one viewcontroller. As I know mapkit require MKMapViewDelegate and tableview require UITableViewDelegate, am I right till this point?
Then does it mean, we can't put mapkit and tableview in one view together?
The things that make me also confused, I did simple app that use textview and mapkit together. I only pass MKMapViewDelegate to view controller. But textview also require delegate to close the keypad using textFieldShouldReturn. So i manage to link the delegate from IB file, but did't pass UITextFieldDelegate to view controller. And it works.
What is the difference if we link the delegate using IB or pass the delegate param to view controller?
Thanks
A view controller CAN be a delegate for both a map view and a table view. An object becomes a delegate simple by implementing the methods of the delegate protocol, in this case that's MKMapViewDelegate and UITableViewDataSource.
An object can implement any number of protocols. You tell the compiler that instances implement a protocol by adding it to the interface:
#interface MyObject : NSObject <UITableViewDataSource, MKMapViewDelegate>
{
...
There is no significant technical difference between setting a delegate in IB and in code. I would advise setting them in IB because using IB reduces the amount of code you write therefore reducing the possibility of your code failing.