2013-04-02 2 views
2

터치시 이미지를 UITableViewCellAccessoryDetailDisclosureButton 변경할 수 있습니까?터치시 상세 정보 표시 이미지 변경

세부 공개 버튼 대신 빈 원이 있도록 tableView에 내 행을 갖고 싶습니다. 이 빈 원 버튼을 탭하면 체크 표시가있는 다른 이미지로 빈 원의 이미지를 변경하고 싶습니다. 그런 다음 약 0.5 초 가량 지연된 후 -accessoryButtonTappedForRowWithIndexPath으로 조치를 취하고 싶습니다.

어떻게하면됩니까?

+0

@GabrielePetronella를 사용할 수 있습니다. 나는이 [링크] (http://iphonedevsdk.com/forum/iphone-sdk-development/71147-change-disclosure-button.html)를 따라 갔다. –

+0

사용자가 "그 반 동안 지연되면 두 번째 "? –

+0

@robmayoff 아무 것도 정말로. 나는 사용자가 이미지의 변화를 인식 할 때까지 약간의 시간을 갖는 것으로 생각했다. –

답변

2

그럼 먼저 사용자 정의 UIView의, 아마있는 UIButton으로 셀의 accessoryView을 설정해야 할 것을 .. . 당신의 tapButton에서

UIImage *uncheckedImage = [UIImage imageNamed:@"Unchecked.png"]; 
UIImage *checkedImage = [UIImage imageNamed:@"Checked.png"]; 
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
button.frame = CGRectMake(44.0, 44.0, image.size.width, image.size.height); 
[button addTarget:self action:@selector(tapButton:) forControlEvents:UIControlEventTouchUpInside]; 
[button setImage:uncheckedImage forState:UIControlStateNormal]; 
[button setImage:checkedImage forState:UIControlStateSelected]; 
cell.accessoryView = button; 

는 : 방법 당신은 이미지에 필요한 변경 사항을 적용하고 accessoryButtonTappedAtIndexPath을 수행 할. 난 그냥 지연을 피할 것 또는 당신은 파견 타이머 ... 나는 이미 빈 원을 가질 수 있도록 버튼을 사용자 정의 할 수 있어요

- (void)tapButton:(UIButton *)button { 
    [button setSelected:!button.selected]; 
    UITableViewCell *cell = [button superview]; 
    NSIndexPath *indexPath = [tableView indexPathForCell:cell]; 
    [self tableView:tableView accessoryButtonTappedForRowWithIndexPath:indexPath]; 

} 
1

귀하의 의견에 따르면 이미 자신의 버튼을 만들고 셀의 accessoryView으로 설정하고 있습니다. 버튼을 만들 때

, 당신의 체크 표시 이미지를 선택한 상태에 대한 자사의 이미지를 설정 :

: 버튼을 탭하면, 그것은 확인 표시가 표시됩니다 있도록 선택에 그 상태를 설정
[button setImage:checkmarkImage forState:UIControlStateSelected]; 

- (IBAction)buttonWasTapped:(id)sender event:(UIEvent *)event { 
    UIButton *button = sender; 
    button.selected = YES; 

그런 다음, 사용자가 지연 동안 다른 작업을 수행 할 수 있도록 해제 사용자 상호 작용 :

[[UIApplication sharedApplication] beginIgnoringInteractionEvents]; 

은 터치 버튼을 포함하는 셀의 인덱스 경로를 가져옵니다 :

마지막으로
UITouch *touch = [[event touchesForView:button] anyObject]; 
    NSIndexPath *indexPath = [tableView indexPathForRowAtPoint: 
     [touch locationInView:tableView]]; 

가 지연 후 실행 블록을 예약합니다. 블록에서 사용자 상호 작용을 재 활성화하고 자신 인덱스 경로를 포함하는 메시지 보내

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), 
     dispatch_get_main_queue(), 
    ^{ 
     [[UIApplication sharedApplication] endIgnoringInteractionEvents]; 
     [self accessoryButtonTappedForRowAtIndexPath:indexPath]; 
    }); 
} 
+0

좋은 해결책. 버튼의 슈퍼 뷰가 셀이라는 것을 알고 있기 때문에 나는 터치 로직을 피할 것이다. 그런 다음 [tableView indexPathForCell : cell]을 호출하여 색인 경로를 가져올 수 있습니다. –

+0

@BenM 버튼을 셀의 직접 하위보기로 사용해서는 안됩니다. 공개 API의 일부가 아닌 구현 세부 사항입니다. 공개 API 만 사용하는 버튼에서 셀로 이동하는 데는 여러 가지 방법이 있습니다. 'indexPathForRowAtPoint :'를 사용하는 것은 간단하고 간단합니다. –

관련 문제