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.
uiviewcontroller
16,312
questions
1500
votes
44
answers
524k
views
Passing data between view controllers
I'm new to iOS and Objective-C and the whole MVC paradigm and I'm stuck with the following:
I have a view that acts as a data entry form and I want to give the user the option to select multiple ...
637
votes
18
answers
306k
views
How to tell if UIViewController's view is visible
I have a tab bar application, with many views. Is there a way to know if a particular UIViewController is currently visible from within the UIViewController? (looking for a property)
351
votes
18
answers
388k
views
Instantiate and Present a viewController in Swift
Issue
I started taking a look on the Swift Programming Language, and somehow I am not able to correctly type the initialization of a UIViewController from a specific UIStoryboard.
In Objective-C I ...
329
votes
11
answers
269k
views
Looking to understand the iOS UIViewController lifecycle
Could you explain me the correct manner to manage the UIViewController lifecycle?
In particular, I would like to know how to use Initialize, ViewDidLoad, ViewWillAppear, ViewDidAppear, ...
285
votes
42
answers
249k
views
How to find topmost view controller on iOS
I've run into a couple of cases now where it would be convenient to be able to find the "topmost" view controller (the one responsible for the current view), but haven't found a way to do it.
...
268
votes
25
answers
169k
views
Programmatically set the initial view controller using Storyboards
How do I programmatically set the InitialViewController for a Storyboard? I want to open my storyboard to a different view depending on some condition which may vary from launch to launch.
257
votes
10
answers
97k
views
Prevent segue in prepareForSegue method?
Is it possible to cancel a segue in the prepareForSegue: method?
I want to perform some check before the segue, and if the condition is not true (in this case, if some UITextField is empty), display ...
254
votes
5
answers
85k
views
Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7
I have been reading a lot about iOS7 UI transition.
I am not able to get what these three properties automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout??
...
253
votes
13
answers
239k
views
iOS - Calling App Delegate method from ViewController
What I am trying to do is click a button (that was created in code) and have it call up a different view controller then have it run a function in the new view controller.
I know it could be done ...
251
votes
29
answers
254k
views
Get top most UIViewController
I can't seem to get the top most UIViewController without access to a UINavigationController. Here is what I have so far:
UIApplication.sharedApplication().keyWindow?.rootViewController?....
234
votes
37
answers
309k
views
Changing the Status Bar Color for specific ViewControllers using Swift in iOS8
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return UIStatusBarStyle.LightContent;
}
Using the above code in any ViewController to set the statusBar color to White for a specific ...
225
votes
8
answers
93k
views
Disable the interactive dismissal of presented view controller
iOS 13 introduces a new design of modalPresentationStyle .pageSheet (and its sibling .formSheet) for modally presented view controllers…
…and we can dismiss these sheets by sliding the presented view ...
211
votes
11
answers
95k
views
Access Container View Controller from Parent iOS
in iOS6 I noticed the new Container View but am not quite sure how to access it's controller from the containing view.
Scenario:
I want to access the labels in Alert view controller from the view ...
210
votes
17
answers
166k
views
Add a UIView above all, even the navigation bar
I want to display, above any other views, even the navigation bar, a kind of "pop-up" view that looks like this:
full screen black background with a 0.5 alpha to see the other UIViewController ...
203
votes
33
answers
244k
views
How to set Status Bar Style in Swift 3
I'm using Xcode 8.0 beta 4.
In previous version, UIViewController have method to set the status bar style
public func preferredStatusBarStyle() -> UIStatusBarStyle
However, I found it changed to ...
201
votes
30
answers
155k
views
Get to UIViewController from UIView?
Is there a built-in way to get from a UIView to its UIViewController? I know you can get from UIViewController to its UIView via [self view] but I was wondering if there is a reverse reference?
170
votes
13
answers
73k
views
Detecting sheet was dismissed on iOS 13
Before iOS 13, presented view controllers used to cover the entire screen. And, when dismissed, the parent view controller viewDidAppear function were executed.
Now iOS 13 will present view ...
168
votes
12
answers
147k
views
Given a view, how do I get its viewController?
I have a pointer to a UIView. How do I access its UIViewController? [self superview] is another UIView, but not the UIViewController, right?
167
votes
4
answers
107k
views
UIViewController viewDidLoad vs. viewWillAppear: What is the proper division of labor?
I have always been a bit unclear on the type of tasks that should be assigned to viewDidLoad vs. viewWillAppear: in a UIViewController subclass.
e.g. I am doing an app where I have a ...
161
votes
17
answers
163k
views
How to check if a view controller is presented modally or pushed on a navigation stack?
How can I, in my view controller code, differentiate between:
presented modally
pushed on navigation stack
Both presentingViewController and isMovingToParentViewController are YES in both cases, so ...
157
votes
6
answers
93k
views
Fatal error: use of unimplemented initializer 'init(coder:)' for class
I decided to continue my remaining project with Swift. When I add the custom class (subclass of UIViewcontroller) to my storyboard view controller and load the project, the app crashes suddenly with ...
156
votes
16
answers
94k
views
Display clearColor UIViewController over UIViewController
I have a UIViewController view as a subview/modal on top of another UIViewController view, such as that the subview/modal should be transparent and whatever components is added to the subview should ...
151
votes
25
answers
109k
views
How do I Disable the swipe gesture of UIPageViewController?
In my case parent UIViewController contains UIPageViewController which contains UINavigationController which contains UIViewController. I need to add a swipe gesture to the last view controller, but ...
150
votes
25
answers
154k
views
Detect when a presented view controller is dismissed
Let's say, I have an instance of a view controller class called VC2. In VC2, there is a "cancel" button that will dismiss itself. But I can't detect or receive any callback when the "cancel" button ...
146
votes
17
answers
169k
views
How to lock orientation of one view controller to portrait mode only in Swift
Since my app got support for all orientation. I would like to lock only portrait mode to specific UIViewController.
e.g. assume it was Tabbed Application and when SignIn View appear modally, I only ...
145
votes
10
answers
177k
views
How to get root view controller?
I need an instance of root view controller.
I tried those approaches:
UIViewController *rootViewController = (UIViewController*)[[[UIApplication sharedApplication] keyWindow] rootViewController];
...
142
votes
6
answers
83k
views
Animate change of view controllers without using navigation controller stack, subviews or modal controllers?
NavigationControllers have ViewController stacks to manage, and limited animation transitions.
Adding a view controller as a sub-view to an existing view controller requires passing events to the sub-...
139
votes
21
answers
80k
views
Completion block for popViewController
When dismissing a modal view controller using dismissViewController, there is the option to provide a completion block. Is there a similar equivalent for popViewController?
The completion argument is ...
138
votes
13
answers
94k
views
viewWillDisappear: Determine whether view controller is being popped or is showing a sub-view controller
I'm struggling to find a good solution to this problem. In a view controller's -viewWillDisappear: method, I need to find a way to determine whether it is because a view controller is being pushed ...
137
votes
20
answers
205k
views
Get the current displaying UIViewController on the screen in AppDelegate.m
The current UIViewController on the screen need to response to push-notifications from APNs, by setting some badge views. But how could I get the UIViewController in methodapplication:...
128
votes
16
answers
27k
views
How to use single storyboard uiviewcontroller for multiple subclass
Let say I have a storyboard that contains UINavigationController as initial view controller. Its root view controller is subclass of UITableViewController, which is BasicViewController. It has ...
127
votes
14
answers
166k
views
Dismissing a Presented View Controller
I have a theoretic question. Now İ'm reading Apple's ViewController guide.
They wrote:
When it comes time to dismiss a presented view controller, the
preferred approach is to let the presenting ...
123
votes
4
answers
100k
views
How do I create a custom iOS view class and instantiate multiple copies of it (in IB)?
I am currently making an app that will have multiple timers, which are basically all the same.
I want to create a custom class that uses all of the code for the timers as well as the layout/...
123
votes
5
answers
93k
views
How do I make a custom initializer for a UIViewController subclass in Swift?
Apologies if this has been asked before, I've searched around a lot and many answers are from earlier Swift betas when things were different. I can't seem to find a definitive answer.
I want to ...
122
votes
5
answers
121k
views
Storyboard - refer to ViewController in AppDelegate
consider the following scenario: I have a storyboard-based app. I add a ViewController object to the storyboard, add the class files for this ViewController into the project and specify the name of ...
120
votes
9
answers
46k
views
how to change uiviewcontroller title independent of tabbar item title
I am setting my view controllers title like this in view did load:
self.title = @"my title";
prior to this I set the title in story boards for the view controller and navigation controller it is ...
119
votes
11
answers
206k
views
UIView touch event in controller
How can I add UIView touchbegin action or touchend action programmatically as Xcode is not providing from Main.storyboard?
115
votes
16
answers
164k
views
Removing viewcontrollers from navigation stack
I have a navigation stack, with say 5 UIViewControllers. I want to remove the 3rd and 4th viewcontrollers in the stack on the click of a button in the 5th viewcontroller. Is it possible to do this? If ...
110
votes
12
answers
137k
views
presentViewController and displaying navigation bar
I have a view controller hierarchy and the top-most controller is displayed as a modal and would like to know how to display the navigation bar when using
'UIViewController:presentViewController:...
110
votes
4
answers
77k
views
Why can't I call the default super.init() on UIViewController in Swift?
I am not using a UIViewController from a storyboard and I want to have a custom init function where I pass in an NSManagedObjectID of some object. I just want to call super.init() like I have in ...
107
votes
2
answers
54k
views
How does View Controller Containment work in iOS 5?
In WWDC 2011 Session 102, Apple introduced View Controller Containment, which is the ability to create custom view controller containers, analogous to UITabBarController, UINavigationController, and ...
105
votes
4
answers
47k
views
What does addChildViewController actually do?
I'm just dipping my feet for the first time into iOS development, and one of the first things I've had to do is implement a custom container view controller - lets call it SideBarViewController - that ...
100
votes
14
answers
82k
views
Custom init for UIViewController in Swift with interface setup in storyboard
I'm having issue for writing custom init for subclass of UIViewController, basically I want to pass the dependency through the init method for viewController rather than setting property directly like ...
97
votes
3
answers
67k
views
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 ...
97
votes
5
answers
22k
views
Leaking views when changing rootViewController inside transitionWithView
While investigating a memory leak I discovered a problem related to the technique of calling setRootViewController: inside a transition animation block:
[UIView transitionWithView:self.window
...
96
votes
8
answers
167k
views
Adding a view controller as a subview in another view controller
I have found few posts for this problem but none of them solved my issue.
Say like I've..
ViewControllerA
ViewControllerB
I tried to add ViewControllerB as a subview in ViewControllerA but, it's ...
95
votes
4
answers
74k
views
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
{
...
95
votes
7
answers
92k
views
Container View Controller Examples [closed]
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 ...
94
votes
8
answers
25k
views
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 ...
93
votes
20
answers
275k
views
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)
...