sorry for bothering you again about the - (void)setNeedsDisplay
which does not call
- (void)drawRect:
method...but I spend so much time on this problem
I am a beginner in Objective-C and I am trying to do a simple shoot-them up. (I know I need to work)
But now, I just want to raise a picture up in the view. For example, the picture appears at (0,0) of the view and I would like this to make this picture go up (of 10 pixels) each time I press a NSButton.
The problem is the picture does not move ;( Some of you can check this out ? Here is the code:
#import <Cocoa/Cocoa.h>
@interface maVue : NSView {
NSImageView * monMonstre;
int nombre;
}
@property (readwrite) int nombre;
- (IBAction)boutonClic:(id)sender;
@end
#import "maVue.h"
@implementation maVue
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
nombre = 2;
monMonstre = [[NSImageView alloc]init];
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
// Drawing code here.
[monMonstre setFrame:CGRectMake(0,[self nombre],100,100)];
[monMonstre setImage:[NSImage imageNamed:@"monstre.jpg"]];
[self addSubview:monMonstre];
}
- (IBAction)boutonClic:(id)sender
{
[self setNombre:[self nombre]+10];
[self setNeedsDisplay:YES];
}
- (void)setNombre:(int)nouveauNombre
{
nombre=nouveauNombre;
}
- (int)nombre
{
return nombre;
}
@end