Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

danmwall

macrumors newbie
Original poster
Apr 13, 2009
17
0
I am a total noob, and for some reason I just can't figure this out. When my program launches or when I switch to a different view (different nib), it loads fine and I can see whatever I designed in the Interface Builder, but I want to perform some functions that impact how the view loads, and I can't figure out how to do that!

For example, I am designing a trivia game. From the main menu of the app, the user selects the option to start playing the game. I load the new screen, but I can't seem to populate the buttons and the labels when the screen first loads! I have to push a button on the screen in order to populate the screen with data and animate the buttons. There has to be a way to eliminate the need to push a button first, but I'm too inexperienced to know what that is.

It seems like I should be able to accomplish that in the viewDidLoad method, but that's not doing the trick.

Can someone help me?? Please??
 

BlackWolf

macrumors regular
Apr 9, 2009
244
0
if viewDidLoad is not doing the trick, you're definetly doing something wrong, because that method is invoked when your view loads (who would have thought?).

do you get any warnings or errors? did you try putting an nslog in your viewDidLoad method like this:
NSLog(@"here we go");
to see if the method is invoked at all?

how do you load your view? are you using a viewcontroller? because viewDidLoad is the method of a UIViewController, not the UIView itself!

maybe you want to post some code you think is relevant.
 

BlackWolf

macrumors regular
Apr 9, 2009
244
0
You could also try the viewWillAppear method.

afaik, viewWillAppear is invoked before the view appears (of course) so you can't be sure all the UILabels and whatnot are already loaded. not 100% sure about this though.

anyway, I go with viewDidAppear to be sure :D

edit: well, no, I use viewDidLoad, but I WOULD use viewDidAppear to be sure ;-)
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
There is both viewWillAppear and viewDidAppear. And you will be fine knowing you have access to labels, etc. in the viewWillAppear since those are set up during the init or the viewDidLoad. (Unless of course you have code where you release these objects before viewWillAppear is called.)
 

danmwall

macrumors newbie
Original poster
Apr 13, 2009
17
0
I was able to execute the code in viewDidLoad, viewDidAppear, and viewWillAppear, but it just wasn't really doing anything to my screens. Because of your suggestions, however, I stumbled across the awakeFromNib function which totally works!!

Thank you, thank you, THANK YOU!!!
 

BlackWolf

macrumors regular
Apr 9, 2009
244
0
I was able to execute the code in viewDidLoad, viewDidAppear, and viewWillAppear, but it just wasn't really doing anything to my screens. Because of your suggestions, however, I stumbled across the awakeFromNib function which totally works!!

Thank you, thank you, THANK YOU!!!

still, the other methods should work as well, so I guess there is still something wrong in your code!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.