Questions tagged [uiviewcontroller]

The UIViewController class manages the views in iOS apps and mediates the interaction between an app's views, its underlying model objects, and the overall workflow.

The UIViewController class manages the views in iOS and watch-os apps and mediates the interaction between an app's views, its underlying model objects, and the overall workflow.

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.

To quote from the Overview of the UIViewController Class Reference:

The UIViewController class provides the fundamental view-management model for all iOS apps. You rarely instantiate UIViewController objects directly. Instead, you instantiate subclasses of the UIViewController class based on the specific task each subclass performs. A view controller manages a set of views that make up a portion of your app’s user interface. As part of the controller layer of your app, a view controller coordinates its efforts with model objects and other controller objects—including other view controllers—so your app presents a single coherent user interface.

References:

16290 questions
128
votes
16 answers

How to use single storyboard uiviewcontroller for multiple subclass

Let say I have a storyboard that contains UINavigationController as initial view controller. Its root view controller is subclass of UITableViewController, which is BasicViewController. It has IBAction which is connected to right navigation button…
Agustinus Verdy
  • 7,267
  • 6
  • 26
  • 28
126
votes
14 answers

Dismissing a Presented View Controller

I have a theoretic question. Now İ'm reading Apple's ViewController guide. They wrote: When it comes time to dismiss a presented view controller, the preferred approach is to let the presenting view controller dismiss it. In other words,…
nikitahils
  • 1,392
  • 2
  • 10
  • 8
122
votes
4 answers

How do I create a custom iOS view class and instantiate multiple copies of it (in IB)?

I am currently making an app that will have multiple timers, which are basically all the same. I want to create a custom class that uses all of the code for the timers as well as the layout/animations, so I can have 5 identical timers that operate…
Michael Campsall
  • 4,325
  • 11
  • 37
  • 52
122
votes
5 answers

Storyboard - refer to ViewController in AppDelegate

consider the following scenario: I have a storyboard-based app. I add a ViewController object to the storyboard, add the class files for this ViewController into the project and specify the name of the new class in the IB identity inspector. Now how…
Matthias D
  • 1,581
  • 2
  • 13
  • 17
121
votes
5 answers

How do I make a custom initializer for a UIViewController subclass in Swift?

Apologies if this has been asked before, I've searched around a lot and many answers are from earlier Swift betas when things were different. I can't seem to find a definitive answer. I want to subclass UIViewController and have a custom initializer…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
120
votes
9 answers

how to change uiviewcontroller title independent of tabbar item title

I am setting my view controllers title like this in view did load: self.title = @"my title"; prior to this I set the title in story boards for the view controller and navigation controller it is embedded in. I set it to: "Title"; When I click on…
Atma
  • 29,141
  • 56
  • 198
  • 299
118
votes
11 answers

UIView touch event in controller

How can I add UIView touchbegin action or touchend action programmatically as Xcode is not providing from Main.storyboard?
dhaval shah
  • 4,499
  • 10
  • 29
  • 42
113
votes
16 answers

Removing viewcontrollers from navigation stack

I have a navigation stack, with say 5 UIViewControllers. I want to remove the 3rd and 4th viewcontrollers in the stack on the click of a button in the 5th viewcontroller. Is it possible to do this? If so how?
Jean Paul
  • 2,389
  • 5
  • 27
  • 37
109
votes
12 answers

presentViewController and displaying navigation bar

I have a view controller hierarchy and the top-most controller is displayed as a modal and would like to know how to display the navigation bar when using 'UIViewController:presentViewController:viewControllerToPresent:animated:completion' The…
108
votes
4 answers

Why can't I call the default super.init() on UIViewController in Swift?

I am not using a UIViewController from a storyboard and I want to have a custom init function where I pass in an NSManagedObjectID of some object. I just want to call super.init() like I have in Objective-C. Like this: init(objectId:…
SirRupertIII
  • 12,324
  • 20
  • 72
  • 121
107
votes
2 answers

How does View Controller Containment work in iOS 5?

In WWDC 2011 Session 102, Apple introduced View Controller Containment, which is the ability to create custom view controller containers, analogous to UITabBarController, UINavigationController, and the like. I watched the examples several times.…
Gregory Higley
  • 15,923
  • 9
  • 67
  • 96
105
votes
4 answers

What does addChildViewController actually do?

I'm just dipping my feet for the first time into iOS development, and one of the first things I've had to do is implement a custom container view controller - lets call it SideBarViewController - that swaps out which of several possible child view…
Mark Amery
  • 143,130
  • 81
  • 406
  • 459
99
votes
14 answers

Custom init for UIViewController in Swift with interface setup in storyboard

I'm having issue for writing custom init for subclass of UIViewController, basically I want to pass the dependency through the init method for viewController rather than setting property directly like viewControllerB.property = value So I made a…
Pigfly
  • 991
  • 1
  • 6
  • 3
97
votes
5 answers

Leaking views when changing rootViewController inside transitionWithView

While investigating a memory leak I discovered a problem related to the technique of calling setRootViewController: inside a transition animation block: [UIView transitionWithView:self.window duration:0.5 …
benzado
  • 82,288
  • 22
  • 110
  • 138
96
votes
8 answers

Adding a view controller as a subview in another view controller

I have found few posts for this problem but none of them solved my issue. Say like I've.. ViewControllerA ViewControllerB I tried to add ViewControllerB as a subview in ViewControllerA but, it's throwing an error like "fatal error: unexpectedly…
Srujan Simha
  • 3,637
  • 8
  • 42
  • 59