All Questions
Tagged with iphone uiviewcontroller
3,549
questions
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?
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 ...
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-...
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:...
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 ...
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 ...
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:...
83
votes
4
answers
34k
views
dismissModalViewController AND pass data back
I have two view controllers, firstViewController and secondViewController. I am using this code to switch to my secondViewController (I am also passing a string to it):
secondViewController *second = ...
80
votes
21
answers
93k
views
How to use presentModalViewController to create a transparent view
I am displaying a modal view with
[self presentModalViewController:controller animated:YES];
When the view moves up the screen it is transparent as per the setting in the xib file it is created from,...
75
votes
8
answers
112k
views
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 ...
74
votes
8
answers
120k
views
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 ...
70
votes
10
answers
23k
views
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 ...
68
votes
14
answers
70k
views
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 ...
67
votes
15
answers
46k
views
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 ...
64
votes
9
answers
82k
views
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' ...
63
votes
3
answers
57k
views
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. ...
62
votes
4
answers
65k
views
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)...
60
votes
6
answers
35k
views
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 ...
58
votes
4
answers
23k
views
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 ...
57
votes
7
answers
26k
views
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 ...
55
votes
6
answers
71k
views
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,...
52
votes
4
answers
81k
views
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, ...
51
votes
4
answers
62k
views
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?
51
votes
14
answers
52k
views
"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 *...
50
votes
9
answers
65k
views
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?
47
votes
22
answers
51k
views
iPhone - dismiss multiple ViewControllers
I have a long View Controllers hierarchy;
in the first View Controller I use this code:
SecondViewController *svc = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]...
47
votes
4
answers
13k
views
In iOS 9, why is SFSafariViewController is being pushed instead of presented modally?
I'm presenting a SFSafariViewController by calling presentViewController:animated:completion: on a UIViewController instance.
The result is that it gets pushed on (slides in from the right), as if ...
45
votes
15
answers
25k
views
How to Dismiss 2 Modal View Controllers in Succession?
I have 2 view controllers presented modally.
A presents B which presents C.
When I dismiss C I would like to dismiss B as well. But I am not sure how to do this:
Dismiss C:
[self ...
45
votes
5
answers
32k
views
When is UIViewController viewDidUnload called?
Note: This question is outdated—viewDidUnload is deprecated iOS 6.
When does UIViewController's viewDidUnload automatically get called? Yes I know, when the view unloads. But when does that happen ...
43
votes
2
answers
38k
views
Use of background/foreground methods in AppDelegate
I'm planning to implement multi-task in my app.
I can see many methods here to do that in the AppDelegate like applicationWillResignActive, applicationDidEnterBackground, ...
42
votes
11
answers
67k
views
How to get the previous viewcontroller that pushed my current view
The home page of my app has UIButtons, btnIncome and btnExpense. Pressing on this buttons pushes IncomeVC and ExpenseVC respectevely,which are two UIViewControllers with UITabBar added via xib. The ...
40
votes
3
answers
35k
views
Add toolbar to UITableViewController
What is the simplest way to add UIToolBar to UITableViewController? I'm depending on edit functionality, so I can't change UITableViewController to UIViewController easily.
38
votes
6
answers
9k
views
UILabel updating stops during scrolling UIScrollView
I have a scrollView with an imageView inside of it. The scrollView is a subView of the superView, and the imageView is a subView of the scrollView.
I also have a label (at the super-view level) that ...
37
votes
5
answers
47k
views
Order of UIViewController initialization and loading
I'm fairly new to UI programming on the Mac and iPhone, and I've run across something that somewhat puzzles me.
A UIViewController has 3 methods that involve the initialization of it and its view:
...
35
votes
5
answers
33k
views
Easiest way to support multiple orientations? How do I load a custom NIB when the application is in Landscape?
I have an application in which I would like to support multiple orientations. I have two .xib files that I want to use, myViewController.xib and myViewControllerLandscape.xib. myViewController.xib ...
34
votes
11
answers
69k
views
UIViewController -viewDidLoad not being called
Being new to Cocoa, I'm having a few issues with Interface Builder, UIViewController and friends.
I have a UIViewController subclass with a UIView defined in a xib, and with the controller's view ...
34
votes
1
answer
48k
views
When to use addChildViewController vs pushViewController
I just watched a 2011 WWDC presentation on "Implementing UIViewController Containment" (here's a link to the video)
They mentioned both of these ways of adding viewControllers to the screen, and I ...
33
votes
7
answers
30k
views
Proper way to hide status bar on iOS, with animation and resizing root view
Consider a view controller that needs to slide out (or hide) the status bar when a button is clicked.
- (void) buttonClick:(id)sender
{
[[UIApplication sharedApplication] setStatusBarHidden:YES
...
33
votes
9
answers
25k
views
How to maintain presenting view controller's orientation when dismissing modal view controller?
I have this app I am working on and I need ALL my view controllers but one to be in portrait.
The single one view controller that is special I need it to be able to rotate to whatever orientation the ...
32
votes
1
answer
9k
views
Am I abusing UIViewController Subclassing?
In trying to figure out why viewWillAppear wasn't being called in my app I came across what may be a gross misunderstanding I hold about the intended use of UIViewController subclasses.
According to ...
31
votes
16
answers
28k
views
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:...
30
votes
5
answers
28k
views
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" ...
30
votes
13
answers
40k
views
How to identify that an UIViewController is presented
I have created an UIViewController sub class which can either be pushed in a navigation stack of a UINavigationController or presented(modally) from any UIViewController. I need to identify whether my ...
30
votes
3
answers
27k
views
UIView vs UIViewController
Ok so i am realllly new to the iphone development and i've gotten pretty far for my knowledge. I just need help deciding how to program these 4-6 pictures into my project.
I basically want to make a ...
30
votes
2
answers
20k
views
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....
29
votes
3
answers
16k
views
Handling app delegates and switching between views
I'm getting a warning about a semantic issue pertaining to passing a *const _strong to type id and cannot seem to fix it no matter what I change.
I have two views at the moment, and have written this ...
29
votes
7
answers
59k
views
Touch events on UITableView?
I have UIViewControllerand UITableView as child in the view,
what I want to do is when I touch any row I am displaying a view at bottom. I want to hide that view if the user touch any where else then ...
29
votes
5
answers
15k
views
How do I override the "view" property in UIViewController?
I have a custom UIViewController and custom UIView. I'd like to override the viewcontroller.view property to return MyCustomUIView.
Right now I have:
@interface MyViewController : UIViewController ...