2013-03-13 5 views
0

사용자 정의 UITableView를 채우는 사용자 정의 셀 (레이블이 5 개)이 있습니다.사용자 정의 셀의 레이블 내용 가져 오기

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //--> Need to get content of each label within the custom cell 
} 

도움을 감사합니다 감사합니다!

답변

1

당신은 그것을 다른 방법

가장 좋은 방법을 할 수있는 것은 서브 뷰 루프를 사용하는 태그

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath]; 

    //get the labels using Tag from cell 
    UILabel *label = ([[cell.contentView viewWithTag:yourTag] isKindOfClass:[UILabel class]])?(UILabel *)[cell.contentView viewWithTag:yourTag]:nil; 


} 

두 번째 방법을 사용하고 있습니다.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath]; 

    for(id subView in [cell.contentView subView]) 
    { 

    if([subViews isKindOfClass:[UILabel class]]) 
    { 
     UILabel *label = (UILabel *)subViews; 
    } 
} 

} 

사용자 지정 셀 클래스 예 :

UILabel *myLabel = [[UILabel alloc] init] 
myLabel.tag = 1; 
[self.contentView addSubView:myLabel]; 
+3

는 사용자 정의 셀이 있다면, 그때 당신이 cell.label1와 가치를 얻을 수있는 가장 쉬운 방법은 각 레이블에 IBOutlets을 가지고 생각 .text, cell.label2.text 등 – rdelmar

+0

사용 안 함 [self.contentView addSubView : myLabel]; 대답을 편집했습니다 ,,, 내 대답은 "사용자 지정 셀 클래스 예제"섹션을 참조하십시오 –

+1

"nope"는 무엇을 의미합니까? 나는 이것을하기위한 대안 방법으로 제 의견을 제시하고 있습니다. 너는 너의 의견을 말할 자격이있어, 나는 내 자격이있어. – rdelmar

관련 문제