2012-04-25 2 views
0

뷰 내에서 동적으로 numberButton 행을 만들었습니다. 숫자를 클릭 할 때 버튼이 강조 표시됩니다. 해당 행에서 1보다 많은 버튼을 클릭하면 클릭 한 모든 버튼이 강조 표시됩니다. 여러 개의 고가 피를 피하기 위해해야 ​​할 일 ? 난 당신이 탭 모든 버튼은 이전의 하이라이트를 제거하지 않고 강조 것을 의미 있으리라 믿고있어태그를 사용하여 동적으로 생성 된 버튼에 배경 이미지를 동적으로 설정하는 방법은 무엇입니까?

-(void)pressed:(id)sender{ 
    UIButton *button = (UIButton *)sender; 
    if(!button.selected){ 

     [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(highlightButton:) userInfo:button repeats:NO];   

    } else { 
     [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(unhighlightButton:) userInfo:button repeats:NO]; 
    } 
-(void)highlightButton:(id)sender{ 
    UIButton *button = (UIButton *)[sender userInfo]; 
    button.highlighted = YES; 
    button.selected = YES; 
} 
-(void)unhighlightButton:(id)sender{ 
    UIButton *button = (UIButton *)[sender userInfo]; 
    button.highlighted = NO; 
    button.selected = NO; 
} 
+0

버튼을 "강조 표시"하고 있습니까? –

답변

1

을 다음과 같이

나는 코드를 사용했다.

한 번에 하나의 버튼 만 강조 표시됩니다. 어떤 버튼이 강조되었는지 추적하고 다른 버튼을 누르면 강조 표시가 제거됩니다.

- (void)buttonTapped:(UIButton *)button { 
    if (button != [self lastSelectedButton]) { // don't re-highlight the same button 
     // remove the highlight of "lastSelectedButton" 

     [self setLastSelectedButton:button]; 
     // add the highlight to "lastSelectedButton" (not updated to the new button) 
    } 

    // Do the rest of you button logic here ... 
} 
+0

죄송합니다 ...이 방법을 사용하여 해결할 수 없습니다. – ani

+0

lastSelectedButton을 저장하려면 속성이 필요합니다.'@property (비 원자력, 약한) UIButton * lastSelectedButton; 그리고 합성하십시오 :'@synthesize lastSelectedButton = _lastSelectedButton; '마지막으로 선택한 버튼을 설정하고 검색 할 수있게하려면 –

+0

예 해결되었습니다. – ani

0

끝에 선택 취소 메소드를 호출하여 select 메소드를 재정의하십시오. 클릭하면 컨트롤이 선택되고 즉시 선택이 해제됩니다.

관련 문제