2012-08-12 2 views

답변

0

tableviewcell 하위 클래스를 만들 때 고유 한 init 메서드를 만들어 부모 뷰의 인스턴스에 대한 포인터를 전달하십시오. 그런 다음 해당 포인터를 인스턴스 변수로 하위 클래스에 저장하십시오. 그렇게하면 하위 클래스에서 무언가가 발생했을 때 부모에게 원하는 것을 할 수 있습니다. 도움이 더 필요하면 알려주세요.

+0

이에 더 정교한 : 대리인의 존재에 대한 UIButton 검사에 대한 작업 방법에

#import <Foundation/Foundation.h> @protocol YourTableViewCellDelegate - (void)didTouchButton:(UIButton *)theButton; @end 

? 예를 들면? 내가 indexpath.row 값을 얻을 수 있는지 확인해야합니다. 이것에 관한 약간의 견본? –

1

당신은보기 계층 구조에서 부모 tableView를 조회 할 수 있습니다

-(UITableView*) parentTableView 
{ 
    UIView* v = [self superview]; 
    while (v && ![v isKindOfClass:[UITableView class]]) { 
     v = [v superview]; 
    } 
    return v; 
} 
0

나는 UITableViewCellsUIViewController 대리자를 설정하는 것이 좋습니다 것입니다. 프로토콜을 만들고 UIViewController 프로토콜을 구현해야합니다. 또한 대리자 속성을 추가하려면 UITableViewCell의 하위 클래스를 만들어야합니다.

if (self.delegate != nil && [self.delegate respondsToSelector:@selector(didTouchButton:)]) { 
    [self.delegate performSelector:@selector(didTouchButton:) withObject:_theButton]; 
}