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
66
votes
6 answers

How do I access my viewController from my appDelegate? iOS

I have an iOS app I created as a "view-based app" in xCode. I have only one viewController, but it is displayed automatically, and I see no code that ties it to my appDelegate. I need to pass data from my appDelegate to my viewController, but…
HackyStack
  • 4,887
  • 3
  • 22
  • 28
64
votes
19 answers

How can I pop specific View Controller in Swift

I used the Objective-C code below to pop a specific ViewController. for (UIViewController *controller in self.navigationController.viewControllers) { if ([controller isKindOfClass:[AnOldViewController class]]) { //Do not forget to…
Mahesh Cheliya
  • 1,334
  • 1
  • 16
  • 21
63
votes
9 answers

Pass data back to previous viewcontroller

I am trying to pass data BACK TO previous viewController. Does anyone know how to pass data back from ViewController B to ViewController A? So I want a string to go 'from' BIDAddTypeOfDealViewController to BIDDCCreateViewController. A user edits…
Anthony
  • 879
  • 3
  • 11
  • 17
63
votes
3 answers

iPhone how to check the type of an Object?

I want to check the type of an Object. How can I do that? The scenario is I'm getting an object. If that object is of type A then do some operations. If it is of type B then do some operations. Currently the type of the object is C that is parent of…
g.revolution
  • 11,962
  • 23
  • 81
  • 107
62
votes
9 answers

Programmatically change rootViewController of storyBoard

I have created my project using Storyboards. The root ViewController lies inside a Storyboard, I have not written a single code in the appDelegate. Now I want to show a tour of my app, so I want to change the root ViewController from Tab Bar to my…
Ranjit
  • 4,576
  • 11
  • 62
  • 121
61
votes
4 answers

How to force layoutSubviews of UIView?

I have a custom UIView which has a dedicated, manually set frame for portrait and landscape orientation because autoresizingMasks just don't work in my case. I set this frame in: - (void)viewWillAppear:(BOOL)animated And it works as expected. My…
myell0w
  • 2,200
  • 2
  • 21
  • 25
60
votes
18 answers

How to change the UINavigationController back button name?

I have a UIViewController and I'm navigating from my first view controller to second view controller and I want to change the name of the button shown on the navigationcontroller for going back .... SecondViewController *secondController =…
Bulla
  • 924
  • 1
  • 7
  • 15
60
votes
11 answers

Current view controller from AppDelegate?

Is there a way to get the current view controller from the AppDelegate? I know there is rootViewController, but that's not what I'm looking for.
aoakenfo
  • 914
  • 1
  • 7
  • 9
60
votes
6 answers

How to press "Back" button in UINavigationController programmatically

I have a UIViewController called FriendsViewController inside a UINavigationController. And a second UIViewController called FriendsDetailedViewController. When navigating from the first view controller to the second, I want to programmatically…
60
votes
3 answers

Getting the top most UIViewController

If I push view controllers and/or present modal view controllers on a UINavigationController, how can I find out what is the top most UIViewController? Or in my case, I want to know if a certain UITableViewController is the top most or not. I tried…
Senseful
  • 86,719
  • 67
  • 308
  • 465
59
votes
3 answers

How to connect ViewController.swift to ViewController in Storyboard?

I made a new view controller in Storyboard and made a new .Swift file that inherits UIViewController. However, my viewDidLoad() is not being called. What do I need to do to connect my view controller in my story board to my .swift code so…
user83039
  • 3,047
  • 5
  • 19
  • 31
59
votes
2 answers

How to add a subview that has its own UIViewController in Objective-C?

I am struggling with subviews that have their own UIViewControllers. I have a UIViewController with a view (light pink) and two buttons on a toolbar. I want blue view to display when the first button is pressed and the yellow view to display with…
Patricia
  • 5,019
  • 14
  • 72
  • 152
58
votes
10 answers

Present modal view controller in half size parent controller

I am trying to present modal view controller on other viewcontroller sized to half parent view controller. But it always present in full screen view. I have created freeform sized View controller in my storyboard with fixed frame size. 320 X…
Anton
  • 3,102
  • 2
  • 28
  • 47
58
votes
11 answers

Get class name of UIViewController in swift

How do you get the class name of a UIViewController class in Swift? In Objective-C, we can do something like this: self.appDelegate = (shAppDelegate *)[[UIApplication sharedApplication] delegate]; UIViewController *last_screen =…
Qadir Hussain
  • 8,721
  • 13
  • 89
  • 124
58
votes
4 answers

Do I have to call addSubview after calling addChildViewController?

I'm trying to create a container view controller using iOS5 and new methods like addChildViewController. Do I have to call addSubview after calling addChildViewController? Do I have to call removeFromSuperview before calling…
Ricardo
  • 2,831
  • 4
  • 29
  • 42