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
1496
votes
44 answers

Passing data between view controllers

I'm new to iOS and Objective-C and the whole MVC paradigm and I'm stuck with the following: I have a view that acts as a data entry form and I want to give the user the option to select multiple products. The products are listed on another view with…
Matt Price
  • 34,499
  • 6
  • 24
  • 33
632
votes
18 answers

How to tell if UIViewController's view is visible

I have a tab bar application, with many views. Is there a way to know if a particular UIViewController is currently visible from within the UIViewController? (looking for a property)
Rob Bonner
  • 9,276
  • 8
  • 35
  • 55
350
votes
18 answers

Instantiate and Present a viewController in Swift

Issue I started taking a look on the Swift Programming Language, and somehow I am not able to correctly type the initialization of a UIViewController from a specific UIStoryboard. In Objective-C I simply write: UIStoryboard *storyboard =…
E-Riddie
  • 14,660
  • 7
  • 52
  • 74
327
votes
11 answers

Looking to understand the iOS UIViewController lifecycle

Could you explain me the correct manner to manage the UIViewController lifecycle? In particular, I would like to know how to use Initialize, ViewDidLoad, ViewWillAppear, ViewDidAppear, ViewWillDisappear, ViewDidDisappear, ViewDidUnload and Dispose…
Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
285
votes
42 answers

How to find topmost view controller on iOS

I've run into a couple of cases now where it would be convenient to be able to find the "topmost" view controller (the one responsible for the current view), but haven't found a way to do it. Basically the challenge is this: Given that one is…
Hot Licks
  • 47,103
  • 17
  • 93
  • 151
267
votes
25 answers

Programmatically set the initial view controller using Storyboards

How do I programmatically set the InitialViewController for a Storyboard? I want to open my storyboard to a different view depending on some condition which may vary from launch to launch.
Jagdev Sendhav
  • 2,875
  • 4
  • 15
  • 24
257
votes
10 answers

Prevent segue in prepareForSegue method?

Is it possible to cancel a segue in the prepareForSegue: method? I want to perform some check before the segue, and if the condition is not true (in this case, if some UITextField is empty), display an error message instead of performing the segue.
Shmidt
  • 16,436
  • 18
  • 88
  • 136
254
votes
5 answers

Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7

I have been reading a lot about iOS7 UI transition. I am not able to get what these three properties automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout?? For example I am trying to make my view controllers…
user1010819
  • 2,691
  • 3
  • 15
  • 14
252
votes
13 answers

iOS - Calling App Delegate method from ViewController

What I am trying to do is click a button (that was created in code) and have it call up a different view controller then have it run a function in the new view controller. I know it could be done relatively easily in IB but that isn't an option. An…
Mytheral
  • 3,929
  • 7
  • 34
  • 57
247
votes
29 answers

Get top most UIViewController

I can't seem to get the top most UIViewController without access to a UINavigationController. Here is what I have so far: UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(vc, animated: true, completion:…
Zoyt
  • 4,809
  • 6
  • 33
  • 45
230
votes
37 answers

Changing the Status Bar Color for specific ViewControllers using Swift in iOS8

override func preferredStatusBarStyle() -> UIStatusBarStyle { return UIStatusBarStyle.LightContent; } Using the above code in any ViewController to set the statusBar color to White for a specific viewcontroller doesnt work in iOS8 for me. Any…
Anuj
  • 6,987
  • 3
  • 22
  • 25
218
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ář
  • 20,070
  • 9
  • 74
  • 84
211
votes
11 answers

Access Container View Controller from Parent iOS

in iOS6 I noticed the new Container View but am not quite sure how to access it's controller from the containing view. Scenario: I want to access the labels in Alert view controller from the view controller that houses the container view. There's a…
Adam Waite
  • 19,175
  • 22
  • 126
  • 148
210
votes
17 answers

Add a UIView above all, even the navigation bar

I want to display, above any other views, even the navigation bar, a kind of "pop-up" view that looks like this: full screen black background with a 0.5 alpha to see the other UIViewController underneath. a UIView window in the middle with some…
Nicolas Roy
  • 3,773
  • 5
  • 27
  • 42
203
votes
33 answers

How to set Status Bar Style in Swift 3

I'm using Xcode 8.0 beta 4. In previous version, UIViewController have method to set the status bar style public func preferredStatusBarStyle() -> UIStatusBarStyle However, I found it changed to a "Get ONLY varaiable" in Swift 3. public var…
Willjay
  • 6,381
  • 4
  • 33
  • 58
1
2 3
99 100