views:

36

answers:

2

I am currently creating my first app for a personal project and I'm having trouble modifying a UILabel's properties when MyViewController is loaded.

From other tutorials, I see that when the nib for my app is unarchived, the initWithCoder app is called:

@synthesize tipText; //references the UILabel i created in my nib file

- (id)initWithCoder:(NSCoder *)coder {

    if (self = [super initWithCoder:coder]) {
        self.tipText.layer.cornerRadius = 8; //the UILabel property i wish to modify
    }

    return self;
}

However, when the above code runs, the tipText is not bound to any memory yet.

Where should i place my self.tipText.layer.cornerRadius code such that tipText is initialized and before the UILabel is displayed in my UI?

A: 

you should implement the following method

-(void)awakeFromNib

and make changes there. This method is called on objects after they are unfrozen from a nib file.

darren
+3  A: 

You want to do this in -[UIViewController viewDidLoad]

Firoze Lafeer
This worked! An example of viewDidLoad can be seen here in the "Implementing viewDidLoad" section:
strife25
http://developer.apple.com/library/ios/#documentation/DataManagement/Conceptual/iPhoneCoreData01/Articles/02_RootViewController.html
strife25