2010-07-12 5 views
0

사용자 정의 UITableViewCells로 구성된 UITableView를 텍스트와 버튼으로 구성했습니다. 셀의 allowSelection 속성이 NO로 설정되어 있으므로 셀을 선택하지 않고 단추를 누를 수 있습니다.UITableView에서 사용자 정의 UITableViewCell의 서브 뷰 선택

해당 셀의 단추를 누를 때 테이블의 어느 셀이 탭되었는지 알 수있는 방법을 찾으려고합니다. 이 일을 할 수있는 방법이 있습니까 ???

많은 감사, 브렛

답변

4

사용이 당신의 UIButton

- (IBAction)buttonTapped:(id)sender { 
    UIButton *button = (UIButton *)sender; 
    UITableViewCell *cell = (UITableViewCell *)button.superview; 
} 

또는 경우

UIButtonUITableViewCellcontentView의 서브 뷰 인 UITableViewCell ( [cell addSubview:button]; 또는 cell.accessoryView = button;)의 직접적인 서브 뷰 인 경우 ( [cell.contentView addSubview:button];) :

- (IBAction)buttonTapped:(id)sender { 
    UIButton *button = (UIButton *)sender; 
    UITableViewCell *cell = (UITableViewCell *)button.superview.superview; 
} 
+0

어떻게하면이 탭 단추가 어느 셀에 있는지 알 수 있습니까? 즉, 두 번째 섹션의 세 번째 셀 또한, 내 단추는 UITableViewCell의 contentView 하위 뷰입니다. – Brett

+0

이것은 셀 자체,'UITableViewCell' 객체를 제공합니다. 그러나이 셀에 대한'indexPath'를 알고 싶다면'NSIndexPath * indexPath = [someTableView indexPathForCell : cell]; '을 사용할 수있다. –

+0

나는 그것을 한 번 줄 것이다! 많은 감사합니다! – Brett

관련 문제