Ios: Differencebetween -Init and -Viewload of a Viewcontroller

What is the difference between presenting a ViewController vs adding a ViewController as a child

The difference is that when you present a controller, it becomes modal, and when you add it as a child controller, it doesn't. The difference is in semantics and use cases.

Modal

As an example of modal window, imagine a window with an OK button in macOS that prevents you from interacting with the parent window until you close it.

Hence why there can be only one view controller presented by a particular controller: the presented controller becomes “main” for user interaction, and the user must close it to return to the parent window.

A typical example of a modal window is an alert.

Child

But a child view controller is a different story. There can be any amount of them on a particular VC.

The parent controller becomes sort of container for child view controllers. For example, there can be a dashboard with multiple panels, and each panel can be a separate controller. This allows to separate logic between different pieces of an application instead of cramming everything into a single controller, to implement user customization in easy way, etc.

A typical example of a parent-child controller interaction is UINavigationController: the navigation controller is the parent, and all view controllers pushed into it are its children. We don't make an uber controller with the whole application's logic, we separate it between different screens, and the navigation controller is only responsible for presentation.

Difference between navigation controller and viewcontroller?

Just my two cents:

A UIViewController represents a single view and you can put buttons in this view controller to segue to another UIViewController. If you want to segue back to the first UIViewController, you will have to worry about putting a button in the second view controller that leads back to the first. If you are drilling down into view controllers, this can be tedious having to remember to give the user a way back to a previous view controller.

A UINavigationController does a lot of this tedious work for you. As mentioned, it contains a stack of UIViewControllers. It will create a navigation bar at the top that will allow you to easily go back up the hierarchy of view controllers.

In short, if you have a hierarchy of view controllers that you want the user to easily navigate around, inbed your UIViewControllers into a UINavigation controller.

Difference between `present` & `push` ViewController

The method you need to use to go back depends on how you showed the view controller.

The first of the two common ways are by using a navigation view controller to push and pop view controllers off the stack.

The other common way is to present and dismiss a view controller modally.

You cannot for example present a view controller modally, and expect to be able to pop it off from the navigation controller, or vice versa.

Difference between viewControllers and childViewControlle for UINavigationController

According to documentation:

public var childViewControllers: [UIViewController] { get }

childViewControllers: An array of view controllers that are children of the current view controller. (read-only). This property does not include any presented view controllers. This property is only intended to be read by an implementation of a custom container view controller.

var viewControllers: [UIViewController] { get set }

viewControllers: The view controllers currently on the navigation stack.

NOTE: A ViewController also have childViewControllers property. but viewControllers property defined in UINavigationController.

What's the difference between UIViewController and ViewController?

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.

What is the difference between UINavigationController.presentViewController and self.presentViewController?

They are analogous - both initiate a modal presentation.

In recent iOS versions, modal presentation always travels to the top most container view controller. So when your view controller (aka self) is container inside a navigation controller (aka self.navigationController), when you attempt presenting on the view controller, it will pass the presentation duties to the navigation controller. You can verify this by logging the presentingController of b once the presentation is completed. In both cases, presentingController will be the navigation controller.

What is the difference between a View and a View Controller?

A view is an object that is drawn to the screen. It may also contain other views (subviews) that are inside it and move with it. Views can get touch events and tell listeners or delegates about any events that occur in them. Views are dumb, and do not know about the structure of your application, and are simply told to display themselves in some state, and listened to for events.

For example: a text label, a button, a checkbox, a progress bar.


A view controller is not drawable to the screen directly, it manages a group of view objects. View controllers usually have a single view with many subviews. The view controller manages the state of these views. A view controller is smart, and it knows how to interact with your application. It tells the dumb view objects what to do and how to show themselves.

For example: a screen that shows a list of users, an edit user form, a login screen.


A view controller is the glue between your overall application and the screen. It controls the views that it owns according to the logic of your application.



Related Topics



Leave a reply



Submit