views:

154

answers:

1

This is probably a very easy question to answer, but for the life of me I can't seem to get this to work.

I'm developing for Mac OS X with Objective-C, and I create a custom class (AppController.h and .m). I hand-wrote two IBOutlets (NSTextField, NSImageView), made sure to do the "@property" line in the .h and the "@synthesize" in the .m file. I made sure to link them in Interface Builder by dragging over a NSObject file and settings its class to AppController, then making the connections.

I don't get any errors, but when I do a very simple call like this: [title setAlphaValue:0.0];

nothing happens. Any light you guys can shed on this would be fantastic.

My code:

AppController.h

#import <Cocoa/Cocoa.h>

@interface AppController : NSObject {
    IBOutlet NSImageView *movie_icon;
    IBOutlet NSTextField *title;

}

-(void)startUp;
@property (nonatomic, retain) NSImageView *movie_icon;
@property (nonatomic, retain) NSTextField *title;

@end

AppController.m

#import "AppController.h"
@implementation AppController
@synthesize title;
@synthesize movie_icon;

-(void)startUp{
     NSLog(@"Starting App Controller...");
     [title setAlphaValue:0.0];
}
@end

main.m

#import <Cocoa/Cocoa.h>
#include "AppController.h"

int main(int argc, char *argv[])
{
    AppController *ctrl;
    ctrl = [[AppController alloc] init];

    [ctrl startUp];
    return NSApplicationMain(argc,  (const char **) argv);
}
A: 

You won't be able to access any of the outlets in your NIB file until after it's fully loaded. Try overriding -awakeFromNib in AppController, and calling -startUp from there.

Ben Gottlieb
That worked! Thank you so much. It would've taken me a long time to figure that out.
MTBPatriot