Questions tagged [viewwillappear]

UIViewController instance method that notifies the view controller that its view is about to be added to a view hierarchy.

View controller subclasses typically override viewWillAppear to perform any tasks to customize the display of the view, based on the context in which the view is being displayed, as described in the documentation.

292 questions
318
votes
7 answers

Why does viewWillAppear not get called when an app comes back from the background?

I'm writing an app and I need to change the view if the user is looking at the app while talking on the phone. I've implemented the following method: - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; …
Philip Walton
  • 29,693
  • 16
  • 60
  • 84
167
votes
4 answers

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 UIViewController subclass hitting a server, getting data, feeding…
dugla
  • 12,774
  • 26
  • 88
  • 136
41
votes
6 answers

Swift viewWillAppear not being called after dismissing view controller

I am presenting a view controller from a view controller called HomeController like so: let viewController = self.storyboard?.instantiateViewController(withIdentifier: "LoginController") as! LoginController let navigationController:…
user979331
  • 11,039
  • 73
  • 223
  • 418
39
votes
2 answers

viewWillAppear, viewDidAppear not being called, not firing

(This is both question and answer since it took quite a bit of digging to find the real answer.) Symptom: viewWillAppear, viewDidAppear were not being called in my UIViewController. Cause: Embedding a UINavigationController or UITabBarController…
pschang
  • 2,568
  • 3
  • 28
  • 23
35
votes
3 answers

What similar functionality method (viewWillAppear) exists on UIView?

viewWillAppear is called on UIViewController when a view is about to be shown on screen. Is it possible to get similar callback on UIView?
Centurion
  • 14,106
  • 31
  • 105
  • 197
33
votes
9 answers

UIViewController viewWillAppear not called when adding as subView

I have a UIViewController that I am loading from inside another view controller and then adding its view to a UIScrollView. self.statisticsController = [self.storyboard…
Fogmeister
  • 76,236
  • 42
  • 207
  • 306
26
votes
3 answers

Can i know in viewWillAppear that it was called after navigationController pop (back button)?

Say I have UIViewController A and B. User navigates from A to B with a push segue. Than user presses back button and comes to A. Now viewWillAppear of A is called. Can I know in the code here that I came from back button (navigationController…
adsurbum
  • 3,107
  • 3
  • 22
  • 27
25
votes
3 answers

Do I programmatically add SubViews in ViewDidAppear, ViewDidLoad, ViewWillAppear, the constructor?

I'm trying to figure out from Apple's sketchy documentation which method is the best place to be initializing and adding my Views controls to the controller's view. With winforms it's fairly straightforward, as they're always initialized inside…
Chris S
  • 64,770
  • 52
  • 221
  • 239
22
votes
6 answers

Swift - func viewWillAppear

I have a standard SingleViewApplication project. ViewController.swift import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view,…
Cristian C.
  • 302
  • 1
  • 2
  • 6
20
votes
2 answers

Guidelines for viewWillAppear, viewDidAppear, viewWillDisappear, viewDidDisappear

Are there any guidelines for using these methods in the right manner? In particular, I would like to know what type of code I could use inside them. For example, if I have to call a method that retrieves data from a WS, where do I have to call it?…
Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
19
votes
4 answers

Navigationbar coloring in ViewWillAppear happens too late in iOS 10

I am facing a weird bug, that happens only on iOS 10. I have a application with several screens, and each screen colors the navigationBar in viewWillAppear. So when you go to the next screen, it will be properly colored. However, when testing on iOS…
Peterdk
  • 15,625
  • 20
  • 101
  • 140
18
votes
8 answers

iOS 8: UITableViewCell detail text not correctly updating

tl;dr: Can I cause the detailTextLabel to have its size updated by the auto layout system in iOS on a value change? Has anyone else had issues with the detailText label within an UITableViewCell since iOS 8? I have a table which both text and detail…
acidaris
  • 190
  • 1
  • 2
  • 6
18
votes
3 answers

iOS: How to know if viewDidLoad got called?

Is there a BOOL or some other way of knowing if viewDidLoad: has been called? I need to change a view property every time my view has entered active, but if the view hasn't ever been loaded, I don't want to prematurely trigger viewDidLoad:. If there…
kev
  • 7,712
  • 11
  • 30
  • 41
17
votes
4 answers

In iOS 6, -[UITextField becomeFirstResponder] doesn't work in -viewWillAppear:

In iOS 5.1 and iOS 5.0 it works, but in iOS 6.0 the keyboard does not show. - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; UITextField *textField = self.emailAddressTextField; [textField…
Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117
11
votes
1 answer

viewDidDisappear not called when use presentViewController

I have an UIViewController having this method: - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; NSLog(@"DISAPPEAR"); lastKnownOrientation = [self interfaceOrientation]; } -(void)openSendVC{ …
Kyle_at_QP
  • 153
  • 1
  • 1
  • 7
1
2 3
19 20