tout le monde! Si quelqu'un peut me aider je serai très heureux ^)Comment changer la variable de classe locale IBAction
Le problème est: Je méthode IBAction (case clic) dans ma classe et je veux changer l'attribut police en cliquant sur la case à cocher (en état gras) . Je essayer de changer variable de classe locale dans la méthode IBAction pour vérifier dans mon - drawRect: méthode, par cela ne fonctionne pas - la variable ne change. Comment changer une variable locale dans la méthode IBAction ou peut-être d'une autre manière? Merci.
#import <Foundation/Foundation.h>
@interface BigLetterView : NSView {
NSColor *bgColor;
NSString *string;
NSString *testString;
BOOL isHighlighted;
BOOL isBold;
BOOL isItalic;
IBOutlet NSButton *boldButton;
NSMutableDictionary *attributes;
}
@property(retain, readwrite) NSColor *bgColor;
@property(copy, readwrite) NSString *string;
@property(readwrite) BOOL isBold;
- (void)drawStringCenteredIn:(NSRect)r;
- (void)prepareAttributes;
- (void)changeIsBold;
- (IBAction)savePDF:(id)sender;
- (IBAction)makeBold:(id)sender; //it's that method
- (IBAction)setItalic:(id)sender;
Ci-dessous variable 'isBold' passe à 'OUI'. (Méthode appelée - test dans le débogueur).
- (IBAction)makeBold:(id)sender
{
if ([boldButton state] == NSOnState) {
isBold = YES;
NSLog(@"Action bold=%d", isBold);
}
else {
isBold = NO;
NSLog(@"Action bold=%d", isBold);
}
}
Mais ici est encore 'NON' à nouveau.
- (void)drawRect:(NSRect)rect {
NSRect bounds = [self bounds];
[bgColor set];
[NSBezierPath fillRect:bounds];
[self drawStringCenteredIn:bounds];
NSLog(@"isBold: %d",isBold); //HERE prints 'isBold:0'
if (isBold == YES) {
NSFont *aFont = [attributes objectForKey:NSFontAttributeName];
NSFontManager *fontManager = [NSFontManager sharedFontManager];
[attributes setObject:[fontManager convertFont:aFont toHaveTrait:NSBoldFontMask] forKey:NSFontAttributeName];
}
//whether this view is firstResponder
if ([[self window] firstResponder] == self &&
[NSGraphicsContext currentContextDrawingToScreen]) {
[NSGraphicsContext saveGraphicsState];
NSSetFocusRingStyle(NSFocusRingOnly);
[NSBezierPath fillRect:bounds];
[NSGraphicsContext restoreGraphicsState];
}
} // drawRect
P.S.I faisant le chapitre 20 du livre d'Aaron Hillegass.
S'il vous plaît nous montrer le code, en particulier comment vous assurez-vous que votre méthode d'action est en effet obtenir appelé. –
Merci pour le commentaire, Ole! C'est fait. – Alexander