UIButtons
이 모두 눌려 졌는지 확인하는 가장 좋은 방법에 대해 빠른 질문이 있습니다.Objective-c에서 가변 개수의 UIButton이 모두 눌려 졌을 때 감지
프로그래밍 방식으로 만든 UIButtons
의 x 번호가 있습니다. 각 버튼은 고유 한 태그가
당신이 버튼을 클릭
가 실행이있다 (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]];
현재 단어는 NSString입니다 (각 버튼은 NSString에서 파생 된 문자입니다).