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
79
votes
11 answers

Opening view controller from app delegate using swift

I am trying to create a push notification which determines which view to open according to information obtained from the push. I have managed to get the information from the push, but I am now struggling to get the view to open Looking at other…
Lister
  • 1,098
  • 1
  • 9
  • 19
79
votes
6 answers

Present and dismiss modal view controller

Can anyone give me the example code that I can use to first present a modal view controller, then dismiss it? This is what I have been trying: NSLog(@"%@", blue.modalViewController); [blue presentModalViewController:red animated:YES]; NSLog(@"%@",…
phunehehe
  • 8,618
  • 7
  • 49
  • 79
78
votes
3 answers

iOS5 Storyboard UIViewController which init method is called by the storyboard?

Which init method is called by the storyboard for UIViewControllers added to the storyboard?
Alex Stone
  • 46,408
  • 55
  • 231
  • 407
77
votes
18 answers

Warning: Attempt to present * on * which is already presenting (null)

This is my first application for iOS. So I have a UIVIewController with a UITableView where I have integrated a UISearchBar and a UISearchController in order to filter TableCells to display override func viewDidLoad() { menuBar.delegate = self …
Splendf
  • 1,611
  • 1
  • 10
  • 8
75
votes
8 answers

Display UIViewController as Popup in iPhone

Since there is no complete, definitive answer to this common recurring question, I'll ask and answer it here. Often we need to present a UIViewController such that it doesn't cover full screen, as in the picture below. Apple provides several…
CRDave
  • 9,279
  • 5
  • 41
  • 59
74
votes
8 answers

How to add an UIViewController's view as subview

Note to googlers, this Q-A is now six years out of date! As Micky below and others mention, this is now done on an everyday basis with Containers in iOS. I have a ViewController which controls many subviews. When I click one of the buttons I…
sperumal
  • 749
  • 1
  • 6
  • 3
74
votes
18 answers

Move UIView up when the keyboard appears in iOS

I have a UIView, it is not inside UIScrollView. I would like to move up my View when the keyboard appears. Before I tried to use this solution: How can I make a UITextField move up when the keyboard is present?. It was working fine. But after…
Anatoliy Gatt
  • 2,501
  • 3
  • 26
  • 42
73
votes
6 answers

iOS7 UIModalTransitionStyleFlipHorizontal bounces after transition

I'm updating my app for iOS 7 and I discovered a weird problem. I'm presenting a UIViewController wrapped in a UINavigationController with UIModalTransitionStyleFlipHorizontal. In iOS 6 it works fine, but in iOS 7 the navigation bar bounces after…
73
votes
7 answers

iOS viewDidLoad for UIView

In a ViewController, there is ViewDidLoad to know when the VC has loaded. For a UIView, what method do i have to use when the view loaded? Would this method be called with any init? edit: No XIB, just programmatically.
manuelBetancurt
  • 15,428
  • 33
  • 118
  • 216
72
votes
8 answers

How to call a View Controller programmatically?

I have looked at all the tutorials I can find on this one, and I still don't have the answer. I need to call another view from the code. I am using UIStoryboards. I have changed the view many times by control-dragging from UIButtons, but now it…
70
votes
11 answers

topLayoutGuide in child view controller

I have a UIPageViewController with translucent status bar and navigation bar. Its topLayoutGuide is 64 pixels, as expected. However, the child view controllers of the UIPageViewController report a topLayoutGuide of 0 pixels, even if they're shown…
hpique
  • 119,096
  • 131
  • 338
  • 476
69
votes
10 answers

CAGradientLayer, not resizing nicely, tearing on rotation

I'm trying to get my CAGradientLayers, that i'm using to create nice gradient backgrounds, to resize nicely on rotation and modal view presentation, but they will not play ball. Here is a video I just created showing my problem: Notice the tearing…
Woodstock
  • 22,184
  • 15
  • 80
  • 118
68
votes
14 answers

How to allow only single UIViewController to rotate in both Landscape and Portrait direction?

My app is only for iphone device (both iphone 4 and 5) and built to support only ios 6. My whole app only supports portrait mode. But there is one view called "ChatView" , which i want to support both landscape and portrait modes. I have set the…
Rohan
  • 2,939
  • 5
  • 36
  • 65
67
votes
8 answers

How to write init methods of a UIViewController in Swift

I am unable to add init method to the following UIViewController class. I need to write some code in the init method. Do i have to write init(coder) method? Even when I add the coder and decoder methods I still get errors. I also tried using the…
Ankit Goel
  • 6,257
  • 4
  • 36
  • 48
66
votes
15 answers

Checking if a UIViewController is about to get Popped from a navigation stack?

I need to know when my view controller is about to get popped from a nav stack so I can perform an action. I can't use -viewWillDisappear, because that gets called when the view controller is moved off screen for ANY reason (like a new view…
Jasarien
  • 58,279
  • 31
  • 157
  • 188