みんな! 誰もが、私は^非常に喜んでいるよ私を助けることができる場合)ローカルクラス変数IBActionを変更するには
問題がある: 私は私のクラスでIBActionメソッド(チェックボックスをクリック)を持っていると私は大胆な状態に(チェックボックスをクリックして、フォント属性を変更したいです) 。 私は私の中でそれをチェックするためIBActionメソッド内のローカルクラス変数を変更しようとしている - のdrawRect:方法を、それが働いていないで - 変数は変更を行いません。 IBActionメソッドでローカル変数を変更する方法や別の方法がありますか?おかげさまで ここで 'YES' から 'isBold' 変化変数以下
#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;
。 (メソッド呼び出し - 私はデバッガでテストします)。
- (IBAction)makeBold:(id)sender
{
if ([boldButton state] == NSOnState) {
isBold = YES;
NSLog(@"Action bold=%d", isBold);
}
else {
isBold = NO;
NSLog(@"Action bold=%d", isBold);
}
}
ただし、ここではisoldはまだ 'いいえ'です。
- (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
アーロン・ヒレガスの本から第20章を行っています。あなたが示されてきたもの
コードを表示してください。特に、あなたの行動方法が本当に呼び出されているかどうかを確認してください。 –
コメントありがとう、Ole!それを行った。 – Alexander