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
32
votes
8 answers

Can't cast value of type UIViewController to PatternDetailViewController

Am trying to downcast a view controller to a detail view controller but can't. Am using Core Data (for the first time). The error is in the prepareForSegue method and reads: "Could not cast value of type 'UIViewController' (0x1b81cdc) to…
pdenlinger
  • 3,897
  • 10
  • 60
  • 92
32
votes
5 answers

How to execute some code after a segue is done?

Is it possible in iOS 6 to know when a UIStoryboardSegue has finished its transition? Like when i add a UIStoryboardSegue from UIButton to push another UIViewController on the navigationcontroler, i want to to something right after the…
bogen
  • 9,954
  • 9
  • 50
  • 89
32
votes
4 answers

Is there a recursiveDescription method for the view controller hierarchy?

recursiveDescription is very useful when debugging a hierarchy of views. View controller hierarchies are also very important, is there an equivalent for this?
jrturton
  • 118,105
  • 32
  • 252
  • 268
31
votes
5 answers

How to constrain autorotation to a single orientation for some views, while allowing all orientations on others?

This question is about iOS device rotation and multiple controlled views in a UINavigationController. Some views should be constrained to portrait orientation, and some should autorotate freely. If you try and create the simplest setup with three…
31
votes
5 answers

Custom init of UIViewController from storyboard

I tried finding some relevant questions but couldn't get anything, hope someone can help. I set up some UIViewController's on a storyboard. I then want to load one of the view controllers in code and push it onto the navigation stack. I figure out…
rafalio
  • 3,928
  • 4
  • 30
  • 33
31
votes
3 answers

Access the instance of a Viewcontroller from another in swift

I am trying to transfer data from the textfield of one View Controller to the label from another. How can I call the View Controller instance from the code of the other View Controller? I'm working with storyboards thus I never created an instance…
McLawrence
  • 4,975
  • 7
  • 39
  • 51
31
votes
5 answers

MFMailComposeViewController in Swift

This is sample code: import UIKit import MessageUI class ViewController: UIViewController, MFMailComposeViewControllerDelegate { @IBAction func showEmail(sender : AnyObject) { var emailTitle = "Test Email" var messageBody =…
Alexey Nakhimov
  • 2,673
  • 8
  • 34
  • 49
31
votes
4 answers

How to set topLayoutGuide position for child view controller

I'm implementing a custom container which is pretty similar to UINavigationController except for it does not hold the whole controller stack. It has a UINavigationBar which is constrained to the container controller's topLayoutGuide, which happens…
Danchoys
  • 739
  • 1
  • 8
  • 14
31
votes
9 answers

Warning: attempt to present ViewController whose view is not in the window hierarchy

In one of my apps, I'm calling a viewController from the application didReceiveLocalNotification method. The page loads successfully, but it shows a warning as : Warning: Attempt to present on …
Vinoy Alexander
  • 810
  • 1
  • 12
  • 24
31
votes
16 answers

iPhone crashing when presenting modal view controller

I'm trying to display a modal view straight after another view has been presented modally (the second is a loading view that appears). - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // Show load LoadViewController…
Michael Waterfall
  • 20,497
  • 27
  • 111
  • 168
31
votes
2 answers

dismissViewControllerAnimated VS popViewControllerAnimated

I want to know what is the different of them. when I can call [self dismissViewControllerAnimated:YES completion:nil]; and when I should call [self.navigationController popViewControllerAnimated:YES]; according document of…
kevin young
  • 941
  • 2
  • 10
  • 22
30
votes
2 answers

UIViewController does not retain its programmatically-created UISearchDisplayController

In the UIViewController documentation about the searchDisplayController property 1 it says: If you create your search display controller programmatically, this property is set automatically by the search display controller when it is…
30
votes
2 answers

Embed UIViewController Programmatically?

I have a Storyboard setup with a UIViewController with an container view so that I can embed another UIViewController inside of it. In a certain scenario I need to change the embedded view controller. In my storyboard I cannot have two segues from…
Josh Kahane
  • 16,765
  • 45
  • 140
  • 253
30
votes
8 answers

Swift - Accessing AppDelegate window from viewController

I make walkthrough (onboarding flow) in my app and I'd like to have a skip button. The button is located on viewController, so I figured out that the best way to move to another viewController would be access app delegate window. However, it keeps…
theDC
  • 6,364
  • 10
  • 56
  • 98
30
votes
5 answers

Why is my NSNotification its observer called multiple times?

Within an App I make use of several viewcontrollers. On one viewcontroller an observer is initialized as follows: [[NSNotificationCenter defaultCenter] removeObserver:self name:@"MyNotification" object:nil]; [[NSNotificationCenter defaultCenter]…
BarryK88
  • 1,806
  • 2
  • 25
  • 41