Search code examples
cocoamacosoutlet

Outlets and instance methods


I have a little problem and hope that you can help me. I want to call a instance method of a subclassed window and set the user interface up there:

//AppDelegate.h
#import <Cocoa/Cocoa.h>

@class MainView;//The main window

@interface DownloadedAppDelegate : NSObject <NSApplicationDelegate> {
    IBOutlet MainView*mainview;//the objects are in the same nib, outlet connected with the window
}

@property(nonatomic,retain) IBOutlet MainView*mainview;

@end

.

//AppDelegate.m
#import "MainView.h"

@synthesize mainview;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[mainview launched];//But sometimes this code fails, I don't know why
//launched sets up the interface
}

-(void)dealloc {
mainview=nil;
}

MainView belongs to NSWindow.

Is there something wrong or something to improve? Should I build up the UI somewhere else? Do you know why this code does not work always?


Solution

  • Try putting

    [mainview launched];
    

    in

    -(void)awakeFromNib {
    

    }