Launch-order of viewcontroller-functions?

Discussion in 'iOS Programming' started by Danneman101, May 20, 2009.

  1. Danneman101 macrumors 6502

    Joined:
    Aug 14, 2008
    #1
    Im trying to determine in which order the various functions of a viewcontroller gets launched.

    In particular, I would like to know which function gets launched BEFORE a tableview's (which is set up by the viewcontroller) cellForRowAtIndexPath-function.

    If I can use any of my preexisting functions, that would be alright. They are:

    - awakeFromNib
    - viewWillAppear
    - numbersOfSectionsInTableView
    - tableview: numberOfRowsInSection
    - viewDidAppear
    - restoreLevel
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    It depends in part when your code calls reloadData. cellForRowAtIndexPath will be called shortly afterwards. awakeFromNib, loadView, viewDidLoad will be called before the table does anything. If you don't call reloadData in any of those methods I think that viewWillAppear and viewDidAppear will be called before your table starts to draw itself, but I'm not certain of that. numbersOfSectionsInTableView and numberOfRowsInSection will probably be called before cellForRowAtIndexPath but that starts to get murky because after the table starts calling its various callbacks the order becomes hard to predict.

    Why do you want to know?
     
  3. Danneman101 thread starter macrumors 6502

    Joined:
    Aug 14, 2008
    #3
    Thanks, I found the reloadData-call in the viewWillAppear-function, and placing my initialization-code before that call made certain that it was in fact executed BEFORE the tableview was populated in the tableView's cellForRowAtIndexPath-function.

    Ive got a drill-down hierachy of tableviews, and Im constructing a system where you can see wether youve visited a page already or not, and in higher hierarchies you should be able to see if youve visited all the pages in the subhierarchy of that cell. And so on. Pretty tedious coding, I must say. Wish there were a built in option in the tableview-class that could accomplish this task, but I havent found any.

    Thanks again for your help :)
     

Share This Page