viewWillAppear not being called?

Discussion in 'iOS Programming' started by dean1012, Oct 5, 2008.

  1. dean1012 macrumors regular

    Joined:
    Jul 10, 2008
    #1
    Hi all,

    I have a tab bar based application in which each tab's view consists of a nav controller and a table view. Each tab works as a drill down.

    The top level views (the views attached to each of the individual tabs) have viewWillAppear called.

    However, when an item on a table view within one of those views is tapped, and subsequently another view is pushed onto the nav controller, viewWillAppear is NOT called.

    No matter what I do I cannot figure out why. Any suggestions?
     
  2. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #2
    Are you defining viewWillAppear properly? It takes a (BOOL)animated property - this one caught me out to begin with.
     
  3. fenrus110 macrumors regular

    Joined:
    Mar 24, 2008
    #3
    in your viewDidLoad, NSLog to check if self.navigationController is null or not
     
  4. dean1012 thread starter macrumors regular

    Joined:
    Jul 10, 2008
    #4
    I am defining viewWillAppear correctly.

    I will check to see if [self navigationController] is null or not but I doubt it is. I use this elsewhere in the same file and it works beautifully.
     
  5. dean1012 thread starter macrumors regular

    Joined:
    Jul 10, 2008
    #5
    more info

    I've *sorta* solved my problem but I am still having two remaining issues.

    First, i'll give a quick background of my setup to give you (hopefully) an exact idea of what i'm seeing.

    I have a tab bar based application with 4 tabs. Each tab contains a navigation controller and table view; each tab operates as a separate drill down. Each tab has 3 drill down levels. The first two are table views and of course the third is a detail view.

    I need viewWillAppear to be called whenever any of those 3 drill down levels will be displayed so I can update the data for that view if needed.

    My original problem was that viewWillAppear was not being called at all. After some online research, I discovered that this is because the navigation controller for each tab needs to have received the viewWillAppear delegate itself before any subviews will receive it. The solution was to place a viewWillAppear method call in each of the 3 view controllers.

    To quickly recap the background before I explain my problems,

    1) tab bar app with 4 tabs
    2) Each tab is separate drill down with 3 levels
    3) Each drill down level has its own view controller
    4) each tab effectively has 3 view controllers that relate to it

    For purposes of my problem, we will take just one of the tabs (once it is solved for one tab it will be solved for all tabs).

    For both problems, assume the following:

    1) The top level of the drill down is the view controller displayed when the tab is selected
    2) The top level of the drill down is viewWillAppearA
    3) The second level of the drill down is viewWillAppearB
    4) The detail view of the drill down is viewWillAppearC


    Problem 1:

    When I tap on the tab, the first view controller is displayed and viewWillAppearA is placed in the console as expected.

    When I drill down to the second level, the second view controller is displayed and viewWillAppearB is placed on the console as expected.

    When I drill down to the detail view, the third view controller is displayed and viewWillAppearC is placed on the console as expected.

    When I drill back up to the second level, the second view controller is displayed and viewWillAppearB is placed on the console as expected.

    Now here is the problem, when I drill back up to the top level, the first view controller is displayed but viewWillAppearA is NOT placed on the console as expected.

    viewWillAppearA only gets called when the tab is selected not when the nav bar controller switches back to the top view.

    Why is this?

    Problem 2:

    The second problem is pretty much like the first. I have an "i" at the top in my nav bar. when it is tapped, I use the app delegate to access the tabBarController and push a modal view ("about") to the screen.

    If the user is on the 2nd level of the drill down and uses that modal button then closes the about view, they will receive two viewWillAppear. viewWillAppearB and viewWillAppearA, in that order.

    And if they are on the detail level view and close it, they receive viewWillAppearC and viewWillAppearA, in that order.

    Ideally, when the modal view is closed, only one viewWillAppear will be called; the delegate for the view that actually will appear.
     
  6. nikih macrumors newbie

    Joined:
    Jul 17, 2009
    #6
    help with same problem

    can you please tell how did you fix that problem because I have the same one, My viewWillAppear is getting executed but whenever I tried to use self.navigationController to dismiss the view nothing happen, so I guess for some reason self.navigationController is not existing yet, because if I use it somewhere else it dismisses the view

    Thank You!!!
     

Share This Page