すべてUIButtons
が押されたかどうかを確認するための最良の方法について簡単な質問があります。
プログラムで作成したx個の番号がUIButtons
あります。各ボタンには独自のタグがあります(100から始まり、上に向かって増加します)。
ボタンをクリックすると、次のように実行されます。
- (void)myButtonAction:(id)sender
{
[self handleButton:sender];
}
- (void)handleButton:(UIButton *)button
{
// ???
}
ユーザーがすべてのボタンをクリックした場合にのみ、インスタンス[self allButtonsClicked]
を実行する必要があります。
これを行うための最良の方法は何ですか?を作成しNSMutableArray
、タグ番号がに含まれているかどうかを確認し、含まれNSMutableArray
ていない場合は追加します。そしてNSMutableArray
、サイズがx個のボタンと等しい場合は、を実行します[self allButtonsClicked]
。
すべてのボタンがクリックされたことを確認する最も簡単な方法は何ですか?
*編集私はそれをタイプした後にそれを理解しました。それを書き出すことは私がそれを得るのを助けました。
-(void)letterreveal: (id)sender {
//data
UIButton *button = (UIButton *)sender;
//action
[self clickcheck:[NSNumber numberWithInt:button.tag]];
}
-(void)clickcheck:(NSNumber*)currenttag {
if ([self.buttonPressCounts containsObject:currenttag]) {
NSLog(@"case A");
}
else {
[self.buttonPressCounts addObject:currenttag];
NSLog(@"case B");
if([self.buttonPressCounts count]==[self.currentword length])
{
NSLog(@"fininshed");
}
}
}
buttonPressCountsはNSMutablearrayです。ボタンを作るときに必ず設定する必要がありました。
self.buttonPressCounts = [NSMutableArray arrayWithCapacity:[self.currentword length]];
currentwordはNSStringです(各ボタンはNSStringから派生した文字です)。