0
votes

Am I doing something wrong here?

If I call my class from the awakeFromNib method I can trace, via a NSLog, that the class is being called up to the initWithFrame method, but the drawRect method is not being called. If I instantiate through an IBAction (say a button) it works fine. Here's the code:

-(void) awakeFromNib { 

[winMain center];

SplashScreen* newSplashScreen = [[SplashScreen alloc] initWithFrame:NSMakeRect(0.0, 0.0, 737.0, 303.0)];

[[[NSApp mainWindow] contentView] addSubview:newSplashScreen];
}

and my SplashScreen.m file:

#import "SplashScreen.h"

@implementation SplashScreen

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
    }
    return self;
}

- (void)drawRect:(NSRect)rect {

    NSImage *imageFromBundle = [NSImage imageNamed:@"sheet1.png"];
    [self setNeedsDisplay:YES];
    [imageFromBundle drawInRect:[self bounds] fromRect:NSMakeRect(0.0, 0.0, 737.0, 303.0) operation: NSCompositeCopy fraction:1.0];
}

@end
1
If you can develop a sample app and make it available somewhere, this would be much easier to figure out.ericg
I posted a file to 4shared, not sure if you have to join to download:4shared.com/file/Kpp2XBM0/Fib2.htmlPruitIgoe

1 Answers

0
votes

Why have you marked the view as needing to be redrawn before you have even drawn anything to the view? This will load the image , mark the view as needing to be redrawn, load the image , mark the view , etc etc etc.... Remove the setNeedsDisplay: And read up on views and memory management.