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
1423
votes
45 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
  • 33,201
  • 6
  • 21
  • 33
592
votes
17 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
  • 8,650
  • 8
  • 32
  • 52
319
votes
16 answers

Instantiate and Present a viewController in Swift

Issue I started taking a look of the new Swift on Xcode 6, and I tried some demo projects and tutorials. Now I am stuck at: Instantiating and then presenting a viewController from a specific storyboard Objective-C Solution UIStoryboard *storyboard =…
E-Riddie
  • 14,052
  • 7
  • 47
  • 70
311
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,006
  • 23
  • 110
  • 185
271
votes
41 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
  • 44,830
  • 15
  • 88
  • 146
262
votes
23 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.
UserDev
  • 2,815
  • 3
  • 13
  • 23
253
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,681
  • 3
  • 13
  • 14
252
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
  • 15,652
  • 16
  • 79
  • 129
250
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,865
  • 7
  • 32
  • 56
218
votes
27 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,313
  • 6
  • 27
  • 44
207
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,748
  • 19
  • 120
  • 146
205
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,537
  • 3
  • 18
  • 24
196
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
  • 5,865
  • 4
  • 30
  • 55
190
votes
29 answers

Get to UIViewController from UIView?

Is there a built-in way to get from a UIView to its UIViewController? I know you can get from UIViewController to its UIView via [self view] but I was wondering if there is a reverse reference?
bertrandom
  • 2,031
  • 2
  • 13
  • 8
188
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,453
  • 5
  • 22
  • 40
1
2 3
99 100