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
57
votes
5 answers

Linking child view controllers to a parent view controller within storyboard

Can you associate child view controllers to a custom container view controller in Storyboard? I can link child view controllers to a tab view controller, and I can link one view controller to a navigation controller. What must I do to the container…
Constantino Tsarouhas
  • 6,846
  • 6
  • 43
  • 54
57
votes
7 answers

What is the process of a UIViewController birth (which method follows which)?

There are many methods to override, like initWithNibname:, awakeFromNib, loadView, viewDidLoad, viewDidAppear:, layoutSubviews, and I just cannot decide in which order gets these method called. I just override one of them "by heart". Any detailed…
Geri Borbás
  • 15,810
  • 18
  • 109
  • 172
56
votes
6 answers

iPhone X hide home indicator on view controller

I have a view controller that takes up the whole screen from top to bottom. I would like to hide the home bar indicator on the bottom of the screen on iPhone X devices. How can I do this in iOS 11?
Vlad
  • 5,727
  • 3
  • 38
  • 59
56
votes
13 answers

iPad custom size of modal view controller

I have a couple of modal view controllers of certain size. I'm trying to avoid the use of custom views (creating full screen black translucent overlay over current view, add the modal view over that view, do the animations, etc) to present it…
emenegro
  • 6,901
  • 10
  • 45
  • 68
55
votes
6 answers

Custom Animation for Pushing a UIViewController

I want to show a custom animation when pushing a view controller: I would like to achieve something like an "expand" animation, that means the new view expands from a given rectangle, lets say [100,100 220,380] during the animation to full…
Erik
  • 11,944
  • 18
  • 87
  • 126
52
votes
4 answers

View Controllers: How to switch between views programmatically?

In short: I want to have two fullscreen views, where I can switch between view A and view B. I know I could just use an Tab Bar Controller, but I dont want to. I want to see how this is done by hand, for learning what's going on under the hood. I…
Thanks
  • 40,109
  • 71
  • 208
  • 322
52
votes
3 answers

In SwiftUI, how to use UIHostingController inside an UIView or as an UIView?

An alternative question title could be "How to add an UIHostingController's view as subview for an UIView?". I am creating a new piece of UI component and would love to give SwiftUI a try. The image below is the current view structure. The UIView is…
XY L
  • 25,431
  • 14
  • 84
  • 143
52
votes
6 answers

Getting the correct bounds of UIViewController's view

I have an iPad-application. In landscape orientation the UIViewController's view actual width = 1024px and height = 768 - 20 (statusBar) - 44 (navigationBar) = 704px. So I wanna get this [1024 x 704] size and I'm using self.view.bounds for it. It…
demon9733
  • 1,054
  • 3
  • 13
  • 35
50
votes
2 answers

viewController custom init method with storyboard

im having trouble overriding the initialization method for my CustomViewController thats designed in my Storyboard. now im doing (in my mainViewController): self.customViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"…
Nicolas S
  • 5,325
  • 3
  • 29
  • 36
50
votes
9 answers

Xcode/iOS5: Move UIView up, when keyboard appears

I'd like to move up my view, when the keyboard is shown. The keyboard (height: 216) should push up my view with it's height. Is this possible with a simple code?
filou
  • 1,609
  • 5
  • 26
  • 53
50
votes
14 answers

"Pushing the same view controller instance more than once is not supported" exception

I am using the following code to retrieve some messages and putting them into my inbox. MyInboxVC *inboxVC=[MyInboxVC get ]; //upload all the pending messages UINavigationController *devNavController=[[MyappMgr get]getDeveloperNavigationController…
Suchi
  • 9,989
  • 23
  • 68
  • 112
50
votes
4 answers

UIViewController's prefersStatusBarHidden not working

I am trying to make the status bar for one of my view controllers to be hidden (when displayed modally). When I'm presenting the view controller, the status bar is is to be hidden and then returned when dismissed. I have added the following code to…
Taz
  • 1,203
  • 1
  • 11
  • 21
50
votes
4 answers

When should I initialize a view controller using initWithNibName?

When should I use init: and when should I use initWithNibName:bundle: when creating a view controller?
Anthony Glyadchenko
  • 3,572
  • 7
  • 48
  • 66
50
votes
6 answers

Can I use autolayout to provide different constraints for landscape and portrait orientations?

Is it possible to change the constraints when the device is rotated? How might this be achieved? A simple example might be two images which, in portrait, are stacked one above the other, but in landscape are side-by-side. If this is not possible,…
Ben Packard
  • 26,102
  • 25
  • 102
  • 183
50
votes
5 answers

xcode storyboard Container View - How do I access the viewcontroller

I'm trying to use storyboard and get things working properly. I've added a a Container View to one of my existing views. When I try to add a reference to this in my view controller .h file (ctrl-drag), I get a IBOutlet UIView *containerView. How do…
Justin808
  • 20,859
  • 46
  • 160
  • 265