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:

16111 questions
166
votes
7 answers

Disable the interactive dismissal of presented view controller

iOS 13 introduces a new design of modalPresentationStyle .pageSheet (and its sibling .formSheet) for modally presented view controllers… …and we can dismiss these sheets by sliding the presented view controller down (interactive dismissal).…
Jakub Truhlář
  • 15,319
  • 7
  • 65
  • 73
165
votes
4 answers

UIViewController viewDidLoad vs. viewWillAppear: What is the proper division of labor?

I have always been a bit unclear on the type of tasks that should be assigned to viewDidLoad vs. viewWillAppear: in a UIViewController subclass. e.g. I am doing an app where I have a UIViewController subclass hitting a server, getting data, feeding…
dugla
  • 12,300
  • 23
  • 79
  • 127
157
votes
6 answers

Fatal error: use of unimplemented initializer 'init(coder:)' for class

I decided to continue my remaining project with Swift. When I add the custom class (subclass of UIViewcontroller) to my storyboard view controller and load the project, the app crashes suddenly with the following error: fatal error: use of…
Pratik Bhiyani
  • 2,489
  • 3
  • 15
  • 26
150
votes
16 answers

Display clearColor UIViewController over UIViewController

I have a UIViewController view as a subview/modal on top of another UIViewController view, such as that the subview/modal should be transparent and whatever components is added to the subview should be visible. The problem is that I have is the…
hightech
  • 3,654
  • 3
  • 22
  • 34
149
votes
12 answers

Given a view, how do I get its viewController?

I have a pointer to a UIView. How do I access its UIViewController? [self superview] is another UIView, but not the UIViewController, right?
mahboudz
  • 38,588
  • 16
  • 95
  • 123
141
votes
6 answers

Animate change of view controllers without using navigation controller stack, subviews or modal controllers?

NavigationControllers have ViewController stacks to manage, and limited animation transitions. Adding a view controller as a sub-view to an existing view controller requires passing events to the sub-view controller, which is a pain to manage,…
TigerCoding
  • 8,660
  • 10
  • 44
  • 72
137
votes
16 answers

How to check if a view controller is presented modally or pushed on a navigation stack?

How can I, in my view controller code, differentiate between: presented modally pushed on navigation stack Both presentingViewController and isMovingToParentViewController are YES in both cases, so are not very helpful. What complicates things is…
135
votes
23 answers

How do I Disable the swipe gesture of UIPageViewController?

In my case parent UIViewController contains UIPageViewController which contains UINavigationController which contains UIViewController. I need to add a swipe gesture to the last view controller, but swipes are handled as if they belong to page view…
135
votes
13 answers

viewWillDisappear: Determine whether view controller is being popped or is showing a sub-view controller

I'm struggling to find a good solution to this problem. In a view controller's -viewWillDisappear: method, I need to find a way to determine whether it is because a view controller is being pushed onto the navigation controller's stack, or whether…
Michael Waterfall
  • 19,942
  • 26
  • 108
  • 161
133
votes
13 answers

Detecting sheet was dismissed on iOS 13

Before iOS 13, presented view controllers used to cover the entire screen. And, when dismissed, the parent view controller viewDidAppear function were executed. Now iOS 13 will present view controllers as a sheet as default, which means the card…
Marcos Tanaka
  • 2,231
  • 3
  • 20
  • 32
129
votes
19 answers

Get the current displaying UIViewController on the screen in AppDelegate.m

The current UIViewController on the screen need to response to push-notifications from APNs, by setting some badge views. But how could I get the UIViewController in methodapplication:didReceiveRemoteNotification: of AppDelegate.m? I tried use…
lu yuan
  • 7,049
  • 9
  • 40
  • 77
124
votes
14 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…
verdy
  • 6,807
  • 6
  • 23
  • 27
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,571
  • 2
  • 13
  • 17
122
votes
20 answers

Completion block for popViewController

When dismissing a modal view controller using dismissViewController, there is the option to provide a completion block. Is there a similar equivalent for popViewController? The completion argument is quite handy. For instance, I can use it to hold…
Ben Packard
  • 24,060
  • 24
  • 94
  • 172
121
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,332
  • 2
  • 10
  • 8