我有一個對象(scaleNotes)的數組,分配給我想要遍歷的按鈕。我希望應用程序等待按下第一組按鈕,然後等待第二組按鈕,等等。但是,目前我的應用程序凍結了該功能。如何等待按鈕按下目標c
包含數組的方法:
-(void)fingerScale :(UIButton*)button1 :(UIButton*)button2 :(UIButton*)button3 :(UIButton*)button4 :(UILabel*)label {
Note *note = [[Note alloc]init];
for (int i = 0; i < [_scaleNotes count]; i++) {
note = _scaleNotes[i];
label.text = note.noteName;
[note waitForNote:button1 :button2 :button3 :button4 :note];
NSLog(@"Waiting... %i", i);
}
}
的「waitForNote」的方法:
-(void)waitForNote:(UIButton *)button1 :(UIButton *)button2 :(UIButton *)button3 :(UIButton *)button4 :(Note*)Note {
bool loop = YES;
while (loop) {
switch ([Note.fingering count]) {
case 0:
loop = NO;
break;
case 1:
button1 = Note.fingering[0];
if (button1.touchInside) {
loop = NO;
}
break;
case 2:
button1 = Note.fingering[0];
button2 = Note.fingering[1];
if (button1.touchInside && button2.touchInside) {
loop = NO;
}
break;
case 3:
button1 = Note.fingering[0];
button2 = Note.fingering[1];
button3 = Note.fingering[2];
if (button1.touchInside && button2.touchInside && button3.touchInside) {
loop = NO;
}
break;
default:
break;
}
}
}
我已被告知,使用addTarget:action:forControlEvents
可以解決我的問題,而不是使用while循環,但我不確定如何將其實施到我的代碼中。請幫忙。
謝謝,我對這門語言仍然很陌生,這非常有幫助。 – Sc0urg3r