문제

I added an imagewell via interface builder, set an image, then ran and all is well. (the image is displayed).

However, if I change the custom class to one of my own (NSImageView subclass), the image is no longer displayed. This is a bare class with nothing added. Any reason why this wouldn't work?

I then tried to manually set an image in the initWithFrame method:

    [self setImage:[NSImage imageNamed:@"image.png"]];
    [self setImageAlignment:NSImageAlignCenter];

    NSLog(@"image is valid? %@", [[self image] isValid] ? @"yes" : @"no");

But this too did not work. No errors, just no image shown.

Any ideas as to what might be my mistake?

도움이 되었습니까?

해결책

Make sure that you call super drawRect inside the drawRect method.

 - (void)drawRect:(NSRect)dirtyRect
 {
     [super drawRect:dirtyRect];
     // Drawing code here.
 }

다른 팁

Check the bindings again, in XIB, Probably you might need to again link ImageView with your New "SubClassImageView"

hope that should solve the problem....

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top