Questions tagged [viewwillappear]
UIViewController instance method that notifies the view controller that its view is about to be added to a view hierarchy.
                                	
	viewwillappear
    
                            
                        
                    
            291
            questions
        
        
            319
            votes
        
        
            7
            answers
        
        
            165k
            views
        
    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 {
    [...
            
        
       
    
            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 ...
            
        
       
    
            43
            votes
        
        
            6
            answers
        
        
            38k
            views
        
    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! ...
            
        
       
    
            39
            votes
        
        
            2
            answers
        
        
            27k
            views
        
    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: ...
            
        
       
    
            35
            votes
        
        
            3
            answers
        
        
            22k
            views
        
    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?
            
        
       
    
            34
            votes
        
        
            9
            answers
        
        
            39k
            views
        
    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 ...
            
        
       
    
            27
            votes
        
        
            3
            answers
        
        
            11k
            views
        
    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 ...
            
        
       
    
            25
            votes
        
        
            3
            answers
        
        
            19k
            views
        
    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 ...
            
        
       
    
            22
            votes
        
        
            6
            answers
        
        
            67k
            views
        
    Swift - func viewWillAppear
                I have a standard SingleViewApplication project.
ViewController.swift
import UIKit
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // ...
            
        
       
    
            20
            votes
        
        
            2
            answers
        
        
            21k
            views
        
    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 ...
            
        
       
    
            19
            votes
        
        
            4
            answers
        
        
            6k
            views
        
    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 ...
            
        
       
    
            18
            votes
        
        
            3
            answers
        
        
            11k
            views
        
    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 ...
            
        
       
    
            18
            votes
        
        
            8
            answers
        
        
            11k
            views
        
    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 ...
            
        
       
    
            17
            votes
        
        
            4
            answers
        
        
            7k
            views
        
    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....
            
        
       
    
            11
            votes
        
        
            4
            answers
        
        
            7k
            views
        
    Android SDK equivlent for viewWillAppear (iOS)?
                Situation
I have a fairly simple app with 2 "layouts" using SharedPreferences.
Main.xml 
Settings.xml
Main has a textView that uses getString from SharedPreferences. Also a button to open Settings.
...
            
        
       
    
            11
            votes
        
        
            1
            answer
        
        
            15k
            views
        
    viewDidDisappear not called when use presentViewController
                I have an UIViewController having this method: 
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    NSLog(@"DISAPPEAR");
    lastKnownOrientation = [self ...
            
        
       
    
            10
            votes
        
        
            4
            answers
        
        
            8k
            views
        
    viewWillAppear in viewcontrollers of a tabbar
                In my tab-bar I have four viewcontrollers, and what happens in one can affect the view of the other, so I may need to reload some elements in the viewcontroller when it becomes visible. Normally I'd ...
            
        
       
    
            10
            votes
        
        
            2
            answers
        
        
            1k
            views
        
    In IOS 4.x or lower, viewDidAppear method is not getting called while adding subview to a view, why?
                In iOS 4.x or lower, viewDidAppear and viewWillAppear, viewDidDisappear and viewWillDisappear, such ViewController's delegate methods are not getting called. The same methods work fine with the iOS 5....
            
        
       
    
            9
            votes
        
        
            7
            answers
        
        
            17k
            views
        
    iOS routing viewDidAppear to child view controllers?
                I'm adding a child view controller to a parent view controller, and everything works as expected, except that child view controller isn't having its usual callbacks triggered. eg, things like ...
            
        
       
    
            9
            votes
        
        
            2
            answers
        
        
            12k
            views
        
    ViewWillAppear on UITableViewCell?
                Is there any way to perform something like ViewWillAppear on UITableViewCell?
UITableViewDelegate methods (like willDisplayCell) only works when cells appear by scrolling.
In my situation, I need to ...
            
        
       
    
            9
            votes
        
        
            2
            answers
        
        
            6k
            views
        
    When exactly should I call [super viewWillAppear:] and when not?
                I have always thought that calling [super viewWillAppear:animated] is mandatory. But today I came across a piece of code from Apple's example application called CoreDataBooks and here's viewWillAppear:...
            
        
       
    
            7
            votes
        
        
            2
            answers
        
        
            754
            views
        
    UIStackView on TitleView Spacing issue after iOS 16
                I have an UIStackView set up on the title view of the navigation bar in my app. It simply shows the icon of the app to the left of the title. In iOS 15 and earlier, this displayed fine. Right now, ...
            
        
       
    
            7
            votes
        
        
            5
            answers
        
        
            10k
            views
        
    Problems with UINavigationController inside of UITabBarController, viewWillAppear not called
                As an overview, I'm having issues with a UINavigationController inside of a UITabBarController calling viewWillAppear whenever a view is popped from the stack. 
From the delegate, a ...
            
        
       
    
            7
            votes
        
        
            3
            answers
        
        
            2k
            views
        
    iPad viewWillAppear and presentModalViewController problems
                In the iPhone, I have a tableview, and touching the cells, I have one method calling presentModalViewController, and opening another view, with email and this kind of stuff. 
When the user press the ...
            
        
       
    
            6
            votes
        
        
            5
            answers
        
        
            19k
            views
        
    About viewController's "viewDidLoad" and "viewWillAppear" methods
                I've got a question regarding the two mentioned methods, since in my tests I don´t make clear the order they are called. I thought that, firstly, viewDidLoad is called when the viewController is ...
            
        
       
    
            6
            votes
        
        
            3
            answers
        
        
            4k
            views
        
    Determine viewWillAppear from Popped UINavigationController or UITabBarController
                I am unable to find a way to distinguish between popping from the Nav controller stack and entering the view controller from the UITabBarController.
I want to call a method in ViewWillAppear only ...
            
        
       
    
            6
            votes
        
        
            2
            answers
        
        
            1k
            views
        
    iOS 9 changed view load behaviour
                I have noticed a change in how iOS 9 loads/displays views compared to previous versions of iOS. Here's an output of self.view.frame in iOS 8.4
viewDidLoad {{0, 0}, {320, 504}}
viewWillAppear {{0, 64},...
            
        
       
    
            6
            votes
        
        
            2
            answers
        
        
            3k
            views
        
    Determine the first time a UIViewController appears
                Before resorting to custom flags I wanted to check this with you people. 
Is there a built-in way to determine in viewWillAppear: or viewWillDisappear: whether the UIViewController is 'newly pushed' ...
            
        
       
    
            5
            votes
        
        
            2
            answers
        
        
            4k
            views
        
    When to put into viewWillAppear and when to put into viewDidLoad?
                I get used to put either of viewWillAppear and viewDidLoad, it's OK until know. However I'm thinking there should be some rules that guide when to put into viewWillAppear and when to put into ...
            
        
       
    
            5
            votes
        
        
            1
            answer
        
        
            2k
            views
        
    Different subview layouts in viewDidLoad and viewWillAppear [duplicate]
                Possible Duplicate:
  UIViewController returns invalid frame?  
While debugging i've noticed that in viewDidLoad call my view frame is origin=(x=0, y=20) size=(width=320, height=460) which is not ...
            
        
       
    
            5
            votes
        
        
            3
            answers
        
        
            5k
            views
        
    popViewController / viewWillAppear not animated in iOS 5
                I wasn't lucky with searching for this, so here we go ;)
I have a UIViewController with a custom UINavigationBar which pushes another UIViewController as subview.
Everything works fine except when I ...
            
        
       
    
            5
            votes
        
        
            2
            answers
        
        
            4k
            views
        
    ViewDidAppear/ViewWillAppear not being called
                I have a ViewController that adds to other subviews which have subclassed uiviewControllers
so Its like this:
mainViewController
       |
  v---------v
subVC1   subVC2
And neither subVC1 or subVC2 ...
            
        
       
    
            5
            votes
        
        
            0
            answers
        
        
            358
            views
        
    tvOS searchController viewWillAppear not being called when navigating back
                So I followed the instructions for the recommended way of adding a search view controller. Basically
let resultsController = storyboard.instantiateViewControllerWithIdentifier(...
            
        
       
    
            4
            votes
        
        
            3
            answers
        
        
            5k
            views
        
    Wrong value for statusBarOrientation on viewWillAppear
                I need to change the image background of a View depending on the orientation. For this, I am using the statusBarOrientation approach in viewWillAppear:
- (void)viewWillAppear:(BOOL)animated
{
    [...
            
        
       
    
            4
            votes
        
        
            2
            answers
        
        
            6k
            views
        
    iOS - Loop through Cells and retrieve data
                Sorry I'm pretty new to iOS dev.
I have a UITableView setup from cells being pulled from a single XiB nib. I've created a on/off switch in the nib, and I am trying to save the state of the switch ...
            
        
       
    
            4
            votes
        
        
            1
            answer
        
        
            4k
            views
        
    Changing NSLayoutContraint constant in viewDidLoad or viewWillAppear don't works
                I am trying to do something like this:
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSLog(@"%@", self.tableViewHeight);
    self.tableViewHeight.constant = 0;
    ...
            
        
       
    
            4
            votes
        
        
            0
            answers
        
        
            340
            views
        
    Changing the key window does not call view will/did dis/appear
                When I change the key window, the rootViewController(s) do not receive view will/did appear/disappear.
    SplashViewController *screenLockViewController = [[SplashViewController alloc] ...
            
        
       
    
            4
            votes
        
        
            1
            answer
        
        
            3k
            views
        
    viewwillappear and viewdidappear not called
                this question is very frequent, but I am not able to solve it with any answers available.
I am working on iOS 5.1. My navigation controller is one tab amongst tab bar view controllers. There's a ...
            
        
       
    
            3
            votes
        
        
            2
            answers
        
        
            7k
            views
        
    Xamarin IOS hide bar back button
                I am trying to hide the back button from my navigationcontroller on a certain view(using storyboard)
I tried to hide the bar back button overriding the ViewWillAppear, but it does not seem to happen.
...
            
        
       
    
            3
            votes
        
        
            3
            answers
        
        
            7k
            views
        
    Is it a MUST for viewWillAppear to have [super viewWillAppear] method as well
                I placed my code for iAd/AdMob ads in...
-(void)viewWillAppear:(BOOL)animated{}
Ads work perfectly fine the way I have them now on all iOS devices.
When I connected my iPhone to Xcode and clicked on ...
            
        
       
    
            3
            votes
        
        
            3
            answers
        
        
            3k
            views
        
    How to avoid viewWillAppear initially calling
                I want to know something aboutViewWillAppear.I have a viewwillappar method for data refreshing. What I want to do is when this viewcontroller push from the previous one this refreshing should not be ...
            
        
       
    
            3
            votes
        
        
            2
            answers
        
        
            1k
            views
        
    Swift viewWillAppear not being called first time usingTabBarController
                So i have a tab bar controller and when I select into the second tab it brings me to a table view controller. I have it setup so that when the viewWillAppear it animates the cells in. The problem I am ...
            
        
       
    
            3
            votes
        
        
            3
            answers
        
        
            2k
            views
        
    Is it necessary to call super in viewWillAppear?
                I am trying to understand the scenario of the method calls to view did/will appear and disappear.
What I did is selecting the table cell (higlights in grey) , go to detail view and go back and ...
            
        
       
    
            3
            votes
        
        
            2
            answers
        
        
            2k
            views
        
    iOS 5.0 view life-cycle issue
                I'm facing strange behaviour of my custom view controller subclasses on iOS 5.0. I'm not using standart navigation controllers etc. in my iPad application, but I'm presenting all view controllers ...
            
        
       
    
            3
            votes
        
        
            1
            answer
        
        
            1k
            views
        
    Why does adding subview in viewDidLoad doesn't work
                I was trying to add UIToolBar into a UIWebView but whenever I insert this code inside viewDidLoad UIToolBar doesn't show up, however when this is done in viewWillAppear, it works. Can someone please ...
            
        
       
    
            3
            votes
        
        
            2
            answers
        
        
            1k
            views
        
    viewWillAppear and UIApplicationDidBecomeActiveNotification
                I am using the UIApplicationDidBecomeActiveNotification to refresh my tableview when the app becomes active.  My problem is that in my ViewWillAppear, I am also calling a method to refresh this table'...
            
        
       
    
            3
            votes
        
        
            2
            answers
        
        
            4k
            views
        
    Why showing and hiding view from viewWillAppear or viewDidAppear doesn't work
                I recently converted an app from modal viewControllers to TabBarController and there is some code that used to work fine before the conversion but now I'm having a hard time making it work in the ...
            
        
       
    
            3
            votes
        
        
            1
            answer
        
        
            4k
            views
        
    Navigationbar not showing on pushing view controller
                I have working on navigation base application.
my problem is that when i am push other view controller into navigation controller .view controller viewWillAppear is not called.
TestCategoryHistory *...
            
        
       
    
            3
            votes
        
        
            2
            answers
        
        
            2k
            views
        
    How to stop viewWillAppear from completing until a function has finished
                I'm pretty new to IOS Application Development.
I'm trying to stop viewWillAppear from finishing until after my function has finished working. How do I do that?
Here's viewWillAppear:
override func ...
            
        
       
    
            3
            votes
        
        
            3
            answers
        
        
            1k
            views
        
    UINavigationBar disappears iOS7
                I have some wierd bug with UINavigationBar.
Sometimes it just disappears (actually if you move view to the half of screen, and then just release it)
Video example
In the first ViewController's ...