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

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
I thought this would have been easy. When launching the program I had an init method that is supposed to change the Title of a button with SetTitle

Code:
@implementation AppController

- (id)init
{
    self = [super init];
    if (self) {
        [self setNameOfButton];
    }
    
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (IBAction)testButton:(id)sender {
    [testButtonNameField setTitle:@"Blah"];
}
-(void)setNameOfButton{
    [testButtonNameField setTitle:@"Blah"];

    
}
@end

It works when I use the code in the method for the button to trigger the event but not on start up? The goal for the night was to have a 'name.txt' file on my website and try to launch the program and have it retrieve the name from the name.txt file.

But I have not gotten that far yet?
 
I solved the problem. It appears that you should not do it in the init method. Instead create the awakeFromNib Method because the outlets are created after the init method and before the awakeFromNib.

Now it functions.
 
I solved the problem. It appears that you should not do it in the init method. Instead create the awakeFromNib Method because the outlets are created after the init method and before the awakeFromNib.

Now it functions.

Correct. You can also manage your UI in -applicationDidFinishLaunching:.
 
WWhich brings up an interesting question. If an AppController object is nib-instantiated, can you even count on the -init method being called? A nib (compiled xib) is a keyed archive, so everything within it should receive -initWithCoder: in lieu of -init, I would think.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.