ユーザーがチェックボックスをクリックすると、ボックスに画像が表示されるインターフェイスを設計しようとしていNSView
ます。12個のチェックボックスがあり、チェックボックスのさまざまな組み合わせをすべて処理するためのifelseステートメントのレイアウトが...頭の中にあります。宣言内にifelseステートメントを配置しました-(void)drawRect:(NSRect)rect
が、機能していないようです。(エラーは発生しません)。プログラムが最初に開始されたときに、ifelseステートメントが正しく評価されることがわかりました。しかし、「」を含むアクションをアクティブにするチェックボックスをクリックするとsetNeedsDisplay:
、「ifelse」ステートメントは再評価されません。(もちろん、それは私がどのように機能するかを正確に理解していないことを意味しますsetNeedsDisplay:
。笑)
NSLog
何が起こっているのかを確認するために、さまざまな場所にいくつかのステートメントを配置しました。-(void)drawRect宣言に、が機能していることを確認するための1つがありsetNeedsDisplay:
ます。そしてそうだった。チェックボックスをクリックするたびに、setNeedsDisplayがアクティブになります。また、「if else」ステートメントの2つの場所に次のように配置NSLog
します。最初の部分に1つ:
- (void)drawRect:(NSRect)rect {
if ([cNatural state] == NSOnState) {
NSLog(@"C Natural Selected");
NSPoint cNaturalPos;
cNaturalPos = NSMakePoint(35, 0);
NSImage * cNaturalImage;
cNaturalImage = [NSImage imageNamed:@"cNatural.png"];
[cNaturalImage dissolveToPoint:cNaturalPos fraction:(1.0)];}
else
if ([dFlat state] == NSOnState) {
NSPoint dFlatPos;
dFlatPos = NSMakePoint(35, 0);
NSImage * dFlatImage;
dFlatImage = [NSImage imageNamed:@"cSharp.png"];
[dFlatImage dissolveToPoint:dFlatPos fraction:(1.0)];}
else
......................
そして、「ifelse」条件の最初のセットの最後に1つあります。
if ([bNatural state] == NSOnState) {
NSPoint bNaturalPos;
bNaturalPos = NSMakePoint(35, 0);
NSImage * bNaturalImage;
bNaturalImage = [NSImage imageNamed:@"bNatural.png"];
[bNaturalImage dissolveToPoint:bNaturalPos fraction:(1.0)];}
else {
NSLog(@"No First Note Selection.");
NSPoint emptyStaffPos;
emptyStaffPos = NSMakePoint(35, 0);
NSImage * emptyStaffImage;
emptyStaffImage = [NSImage imageNamed:@"emptyStaff.png"];
[emptyStaffImage dissolveToPoint:emptyStaffPos fraction:(1.0)];}
プログラムが最初にロードされたときに、「最初のノートの選択なし」がコンソールに表示されると思います。そして、そうです。「cNatural」チェックボックスをアクティブにすると、代わりにコンソールに「NoFirstNoteSelection」文字列が表示されます。チェックボックスの状態変化を登録していないようです。
Interface Builderでチェックボックスが正しく接続されていることを確認するために、チェックボックスが切り替えられたときにアクティブになるこのコード行を作成しました:(このコードにはsetNeedsDisplay:
)も含まれています
- (IBAction)rendStaffCanvas:(id)sender {
[staffDrawingCanvas setNeedsDisplay:YES];
if ([cNatural state] == NSOnState) {
NSLog(@"C Natural checkbox: ON");
}
else {
NSLog(@"C Natural checkbox: OFF");
}
if ([dFlat state] == NSOnState) {
NSLog(@"D Flat checkbox: ON");
}
else {
NSLog(@"D Flat checkbox: OFF");
}
if ([dNatural state] == NSOnState) {
NSLog(@"D Natural checkbox: ON");
}
これらはすべてコンソールで期待どおりに表示されますが、-(void)drawRect
一部の「ifelse」ステートメントは登録されていないようです。
私はいたるところを見てきましたが、これに対する解決策を見つけることができません。どんな助けでも大歓迎です。
これが私の.mファイルのかなり長いコードです:
#import "StaffCanvas.h"
@implementation StaffCanvas
- (IBAction)rendStaffCanvas:(id)sender {
[staffDrawingCanvas setNeedsDisplay:YES];
if ([cNatural state] == NSOnState) {
NSLog(@"C Natural checkbox: ON");
}
else {
NSLog(@"C Natural checkbox: OFF");
}
if ([dFlat state] == NSOnState) {
NSLog(@"D Flat checkbox: ON");
}
else {
NSLog(@"D Flat checkbox: OFF");
}
if ([dNatural state] == NSOnState) {
NSLog(@"D Natural checkbox: ON");
}
else {
NSLog(@"D Natural checkbox: OFF");
}
if ([eFlat state] == NSOnState) {
NSLog(@"E Flat checkbox: ON");
}
else {
NSLog(@"E Flat checkbox: OFF");
}
if ([eNatural state] == NSOnState) {
NSLog(@"E Natural checkbox: ON");
}
else {
NSLog(@"E Natural checkbox: OFF");
}
if ([fNatural state] == NSOnState) {
NSLog(@"F Natural checkbox: ON");
}
else {
NSLog(@"F Natural checkbox: OFF");
}
if ([gFlat state] == NSOnState) {
NSLog(@"G Flat checkbox: ON");
}
else {
NSLog(@"G Flat checkbox: OFF");
}
if ([gNatural state] == NSOnState) {
NSLog(@"G Natural checkbox: ON");
}
else {
NSLog(@"G Natural checkbox: OFF");
}
if ([aFlat state] == NSOnState) {
NSLog(@"A Flat checkbox: ON");
}
else {
NSLog(@"A Flat checkbox: OFF");
}
if ([aNatural state] == NSOnState) {
NSLog(@"A Natural checkbox: ON");
}
else {
NSLog(@"A Natural checkbox: OFF");
}
if ([bFlat state] == NSOnState) {
NSLog(@"B Flat checkbox: ON");
}
else {
NSLog(@"B Flat checkbox: OFF");
}
if ([bNatural state] == NSOnState) {
NSLog(@"B Natural checkbox: ON");
}
else {
NSLog(@"B Natural checkbox: OFF");
}
}
- (void)drawRect:(NSRect)rect {
if ([cNatural state] == NSOnState) {
NSLog(@"C Natural Selected");
NSPoint cNaturalPos;
cNaturalPos = NSMakePoint(35, 0);
NSImage * cNaturalImage;
cNaturalImage = [NSImage imageNamed:@"cNatural.png"];
[cNaturalImage dissolveToPoint:cNaturalPos fraction:(1.0)];}
else
if ([dFlat state] == NSOnState) {
NSPoint dFlatPos;
dFlatPos = NSMakePoint(35, 0);
NSImage * dFlatImage;
dFlatImage = [NSImage imageNamed:@"cSharp.png"];
[dFlatImage dissolveToPoint:dFlatPos fraction:(1.0)];}
else
if ([dNatural state] == NSOnState) {
NSPoint dNaturalPos;
dNaturalPos = NSMakePoint(35, 0);
NSImage * dNaturalImage;
dNaturalImage = [NSImage imageNamed:@"dNatural.png"];
[dNaturalImage dissolveToPoint:dNaturalPos fraction:(1.0)];}
else
if ([eFlat state] == NSOnState) {
NSPoint eFlatPos;
eFlatPos = NSMakePoint(35, 0);
NSImage * eFlatImage;
eFlatImage = [NSImage imageNamed:@"eFlat.png"];
[eFlatImage dissolveToPoint:eFlatPos fraction:(1.0)];}
else
if ([eNatural state] == NSOnState) {
NSPoint eNaturalPos;
eNaturalPos = NSMakePoint(35, 0);
NSImage * eNaturalImage;
eNaturalImage = [NSImage imageNamed:@"eNatural.png"];
[eNaturalImage dissolveToPoint:eNaturalPos fraction:(1.0)];}
else
if ([fNatural state] == NSOnState) {
NSPoint fNaturalPos;
fNaturalPos = NSMakePoint(35, 0);
NSImage * fNaturalImage;
fNaturalImage = [NSImage imageNamed:@"fNatural.png"];
[fNaturalImage dissolveToPoint:fNaturalPos fraction:(1.0)];}
else
if ([gFlat state] == NSOnState) {
NSPoint fSharpPos;
fSharpPos = NSMakePoint(35, 0);
NSImage * fSharpImage;
fSharpImage = [NSImage imageNamed:@"fSharp.png"];
[fSharpImage dissolveToPoint:fSharpPos fraction:(1.0)];}
else
if ([gNatural state] == NSOnState) {
NSPoint gNaturalPos;
gNaturalPos = NSMakePoint(35, 0);
NSImage * gNaturalImage;
gNaturalImage = [NSImage imageNamed:@"gNatural.png"];
[gNaturalImage dissolveToPoint:gNaturalPos fraction:(1.0)];}
else
if ([aFlat state] == NSOnState) {
NSPoint aFlatPos;
aFlatPos = NSMakePoint(35, 0);
NSImage * aFlatImage;
aFlatImage = [NSImage imageNamed:@"aFlat.png"];
[aFlatImage dissolveToPoint:aFlatPos fraction:(1.0)];}
else
if ([aNatural state] == NSOnState) {
NSPoint aNaturalPos;
aNaturalPos = NSMakePoint(35, 0);
NSImage * aNaturalImage;
aNaturalImage = [NSImage imageNamed:@"aNatural.png"];
[aNaturalImage dissolveToPoint:aNaturalPos fraction:(1.0)];}
else
if ([bFlat state] == NSOnState) {
NSPoint bFlatPos;
bFlatPos = NSMakePoint(35, 0);
NSImage * bFlatImage;
bFlatImage = [NSImage imageNamed:@"bFlat.png"];
[bFlatImage dissolveToPoint:bFlatPos fraction:(1.0)];}
else
if ([bNatural state] == NSOnState) {
NSPoint bNaturalPos;
bNaturalPos = NSMakePoint(35, 0);
NSImage * bNaturalImage;
bNaturalImage = [NSImage imageNamed:@"bNatural.png"];
[bNaturalImage dissolveToPoint:bNaturalPos fraction:(1.0)];}
else {
NSLog(@"No First Note Selection.");
NSPoint emptyStaffPos;
emptyStaffPos = NSMakePoint(35, 0);
NSImage * emptyStaffImage;
emptyStaffImage = [NSImage imageNamed:@"emptyStaff.png"];
[emptyStaffImage dissolveToPoint:emptyStaffPos fraction:(1.0)];}
if ([dFlat state] == NSOnState) {
NSPoint dFlatPos;
dFlatPos = NSMakePoint(70, 0);
NSImage * dFlatImage;
dFlatImage = [NSImage imageNamed:@"cSharp.png"];
[dFlatImage dissolveToPoint:dFlatPos fraction:(1.0)];}
else
if ([dNatural state] == NSOnState) {
NSPoint dNaturalPos;
dNaturalPos = NSMakePoint(70, 0);
NSImage * dNaturalImage;
dNaturalImage = [NSImage imageNamed:@"dNatural.png"];
[dNaturalImage dissolveToPoint:dNaturalPos fraction:(1.0)];}
else
if ([eFlat state] == NSOnState) {
NSPoint eFlatPos;
eFlatPos = NSMakePoint(70, 0);
NSImage * eFlatImage;
eFlatImage = [NSImage imageNamed:@"eFlat.png"];
[eFlatImage dissolveToPoint:eFlatPos fraction:(1.0)];}
else
if ([eNatural state] == NSOnState) {
NSPoint eNaturalPos;
eNaturalPos = NSMakePoint(70, 0);
NSImage * eNaturalImage;
eNaturalImage = [NSImage imageNamed:@"eNatural.png"];
[eNaturalImage dissolveToPoint:eNaturalPos fraction:(1.0)];}
else
if ([fNatural state] == NSOnState) {
NSPoint fNaturalPos;
fNaturalPos = NSMakePoint(70, 0);
NSImage * fNaturalImage;
fNaturalImage = [NSImage imageNamed:@"fNatural.png"];
[fNaturalImage dissolveToPoint:fNaturalPos fraction:(1.0)];}
else
if ([gFlat state] == NSOnState) {
NSPoint fSharpPos;
fSharpPos = NSMakePoint(70, 0);
NSImage * fSharpImage;
fSharpImage = [NSImage imageNamed:@"fSharp.png"];
[fSharpImage dissolveToPoint:fSharpPos fraction:(1.0)];}
else
if ([gNatural state] == NSOnState) {
NSPoint gNaturalPos;
gNaturalPos = NSMakePoint(70, 0);
NSImage * gNaturalImage;
gNaturalImage = [NSImage imageNamed:@"gNatural.png"];
[gNaturalImage dissolveToPoint:gNaturalPos fraction:(1.0)];}
else
if ([aFlat state] == NSOnState) {
NSPoint aFlatPos;
aFlatPos = NSMakePoint(70, 0);
NSImage * aFlatImage;
aFlatImage = [NSImage imageNamed:@"aFlat.png"];
[aFlatImage dissolveToPoint:aFlatPos fraction:(1.0)];}
else
if ([aNatural state] == NSOnState) {
NSPoint aNaturalPos;
aNaturalPos = NSMakePoint(70, 0);
NSImage * aNaturalImage;
aNaturalImage = [NSImage imageNamed:@"aNatural.png"];
[aNaturalImage dissolveToPoint:aNaturalPos fraction:(1.0)];}
else
if ([bFlat state] == NSOnState) {
NSPoint bFlatPos;
bFlatPos = NSMakePoint(70, 0);
NSImage * bFlatImage;
bFlatImage = [NSImage imageNamed:@"bFlat.png"];
[bFlatImage dissolveToPoint:bFlatPos fraction:(1.0)];}
else
if ([bNatural state] == NSOnState) {
NSPoint bNaturalPos;
bNaturalPos = NSMakePoint(70, 0);
NSImage * bNaturalImage;
bNaturalImage = [NSImage imageNamed:@"bNatural.png"];
[bNaturalImage dissolveToPoint:bNaturalPos fraction:(1.0)];}
else {
NSPoint emptyStaffPos;
emptyStaffPos = NSMakePoint(70, 0);
NSImage * emptyStaffImage;
emptyStaffImage = [NSImage imageNamed:@"emptyStaff.png"];
[emptyStaffImage dissolveToPoint:emptyStaffPos fraction:(1.0)];}
if ([dNatural state] == NSOnState) {
NSPoint dNaturalPos;
dNaturalPos = NSMakePoint(105, 0);
NSImage * dNaturalImage;
dNaturalImage = [NSImage imageNamed:@"dNatural.png"];
[dNaturalImage dissolveToPoint:dNaturalPos fraction:(1.0)];}
else
if ([eFlat state] == NSOnState) {
NSPoint eFlatPos;
eFlatPos = NSMakePoint(105, 0);
NSImage * eFlatImage;
eFlatImage = [NSImage imageNamed:@"eFlat.png"];
[eFlatImage dissolveToPoint:eFlatPos fraction:(1.0)];}
else
if ([eNatural state] == NSOnState) {
NSPoint eNaturalPos;
eNaturalPos = NSMakePoint(105, 0);
NSImage * eNaturalImage;
eNaturalImage = [NSImage imageNamed:@"eNatural.png"];
[eNaturalImage dissolveToPoint:eNaturalPos fraction:(1.0)];}
else
if ([fNatural state] == NSOnState) {
NSPoint fNaturalPos;
fNaturalPos = NSMakePoint(105, 0);
NSImage * fNaturalImage;
fNaturalImage = [NSImage imageNamed:@"fNatural.png"];
[fNaturalImage dissolveToPoint:fNaturalPos fraction:(1.0)];}
else
if ([gFlat state] == NSOnState) {
NSPoint fSharpPos;
fSharpPos = NSMakePoint(105, 0);
NSImage * fSharpImage;
fSharpImage = [NSImage imageNamed:@"fSharp.png"];
[fSharpImage dissolveToPoint:fSharpPos fraction:(1.0)];}
else
if ([gNatural state] == NSOnState) {
NSPoint gNaturalPos;
gNaturalPos = NSMakePoint(105, 0);
NSImage * gNaturalImage;
gNaturalImage = [NSImage imageNamed:@"gNatural.png"];
[gNaturalImage dissolveToPoint:gNaturalPos fraction:(1.0)];}
else
if ([aFlat state] == NSOnState) {
NSPoint aFlatPos;
aFlatPos = NSMakePoint(105, 0);
NSImage * aFlatImage;
aFlatImage = [NSImage imageNamed:@"aFlat.png"];
[aFlatImage dissolveToPoint:aFlatPos fraction:(1.0)];}
else
if ([aNatural state] == NSOnState) {
NSPoint aNaturalPos;
aNaturalPos = NSMakePoint(105, 0);
NSImage * aNaturalImage;
aNaturalImage = [NSImage imageNamed:@"aNatural.png"];
[aNaturalImage dissolveToPoint:aNaturalPos fraction:(1.0)];}
else
if ([bFlat state] == NSOnState) {
NSPoint bFlatPos;
bFlatPos = NSMakePoint(105, 0);
NSImage * bFlatImage;
bFlatImage = [NSImage imageNamed:@"bFlat.png"];
[bFlatImage dissolveToPoint:bFlatPos fraction:(1.0)];}
else
if ([bNatural state] == NSOnState) {
NSPoint bNaturalPos;
bNaturalPos = NSMakePoint(105, 0);
NSImage * bNaturalImage;
bNaturalImage = [NSImage imageNamed:@"bNatural.png"];
[bNaturalImage dissolveToPoint:bNaturalPos fraction:(1.0)];}
else {
NSPoint emptyStaffPos;
emptyStaffPos = NSMakePoint(105, 0);
NSImage * emptyStaffImage;
emptyStaffImage = [NSImage imageNamed:@"emptyStaff.png"];
[emptyStaffImage dissolveToPoint:emptyStaffPos fraction:(1.0)];}
NSLog(@"Redisplayed.");
NSPoint clefPos;
clefPos = NSMakePoint(0, 0);
NSImage * clefImage;
clefImage = [NSImage imageNamed:@"clefStart.png"];
[clefImage dissolveToPoint:clefPos fraction:(1.0)];
}
@end