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
96
votes
3 answers

iOS Nested View Controllers view inside UIViewController's view?

Is it typically bad programming practice in iOS to have a nested view controller's view inside UIViewController's view? Say for instance I wanted to have some kind of interactive element that responds to user's touches, but only takes up maybe 25%…
Skyler
  • 2,834
  • 5
  • 22
  • 34
95
votes
7 answers

Container View Controller Examples

Can anyone point me to any good examples of creating a Custom View Controller as a Container View Controller? The only documentation I can find is a couple of paragraphs in the UIViewController Class Reference. I feel I need a little more…
Undistraction
  • 42,754
  • 56
  • 195
  • 331
95
votes
4 answers

Swift: Custom ViewController initializers

How do you add custom initializers to UIViewController subclasses in Swift? I've created a sub class of UIViewController that looks something like this: class MyViewController : UIViewController { init(leftVC:UIViewController,…
BadmintonCat
  • 9,416
  • 14
  • 78
  • 129
94
votes
8 answers

presentViewController:animated:YES view will not appear until user taps again

I'm getting some strange behaviour with presentViewController:animated:completion. What I'm making is essentially a guessing game. I have a UIViewController (frequencyViewController) containing a UITableView (frequencyTableView). When the user taps…
HalfNormalled
  • 943
  • 1
  • 7
  • 6
93
votes
20 answers

Programmatically navigate to another view controller/scene

I got an error message during navigating from first view controller to second view controller. My coding is like this one let vc = LoginViewController(nibName: "LoginViewController", bundle: nil) self.navigationController?.pushViewController(vc,…
Nurdin
  • 23,382
  • 43
  • 130
  • 308
89
votes
21 answers

Popover with embedded navigation controller doesn't respect size on back nav

I have a UIPopoverController hosting a UINavigationController, which contains a small hierarchy of view controllers. I followed the docs and for each view controller, I set the view's popover-context size like so: [self…
Ben Zotto
  • 70,108
  • 23
  • 141
  • 204
89
votes
21 answers

Force landscape mode in one ViewController using Swift

I am trying to force only one view in my application on landscape mode, I am calling: override func shouldAutorotate() -> Bool { print("shouldAutorotate") return false } override func supportedInterfaceOrientations() -> Int { …
sazz
  • 3,193
  • 3
  • 23
  • 33
83
votes
4 answers

dismissModalViewController AND pass data back

I have two view controllers, firstViewController and secondViewController. I am using this code to switch to my secondViewController (I am also passing a string to it): secondViewController *second = [[secondViewController alloc] initWithNibName:nil…
Andrew Davis
  • 2,310
  • 1
  • 24
  • 43
82
votes
6 answers

modal View controllers - how to display and dismiss

I'm breaking my head for the last one week on how to solve the issue with showing and dismissing multiple view controllers. I have created a sample project and pasting the code directly from the project. I have 3 view controllers with their…
81
votes
10 answers

Move or copy view controller from one storyboard to another

I have several UIViewControllers in one Storyboard. Now I want to move some UIViewControllers to another Storyboard. Is it possible?
Vladimir Berezkin
  • 3,580
  • 4
  • 27
  • 33
80
votes
21 answers

How to use presentModalViewController to create a transparent view

I am displaying a modal view with [self presentModalViewController:controller animated:YES]; When the view moves up the screen it is transparent as per the setting in the xib file it is created from, but once it fills the screen it goes opaque. Is…
Darryl Braaten
  • 5,229
  • 4
  • 36
  • 50
80
votes
14 answers

Swift - How to dismiss all of view controllers to go back to root

I want a my app can go to a first view controller when every time users want it. So I want to create a function to dismiss all the view controllers, regardless of whether it is pushed in navigation controllers or presented modally or opened anything…
Byoth
  • 1,905
  • 6
  • 16
  • 28
79
votes
9 answers

Storyboard Segue From View Controller to Itself

I am trying to make a mechanism to drill down a file / folder list. The idea is to show the same file list view controller every time the user selects a folder, and show a file detail view controller if he/she selects a file. So far, I have created…
Jorge
  • 2,530
  • 1
  • 19
  • 28
79
votes
17 answers

How to identify previous view controller in navigation stack

I have 2 seperate navigationcontrollers, one with RootViewController A and the other with RootViewController B. I am able to push ViewController C onto either A or B's navigation stack. Question: When I am in ViewController C, how can I find out if…
Zhen
  • 12,361
  • 38
  • 122
  • 199
79
votes
11 answers

single function to dismiss all open view controllers

I have an app which is a single view application. I have a navigation controller linked up to all child controllers from the root view controller. In each child controller, I have a logout button. I'm wondering if I can have a single function I can…
user2363025
  • 6,365
  • 19
  • 48
  • 89