2017-01-27 4 views
1

내 문제는 내가 정의하려고하는 것이 조금 복잡하다. 나는이 문제를 이해하기 쉽게 작성하려고 최선을 다한다. .TableViewCell의 다른 TableViewCell의 레이블 레이블

그래서 문제는 내가 UITableViewCell 안에 UITableView이 있고, UITableViews에 모두 UITableViewCell 클래스가 있습니다. 데이터 소스와 저녁 외식 모두 UITableView 님의 동급생입니다. UILabel (. 예를 들어 myLabel), UITableView (내부)

  • UITableViewCell 사용자 정의 클래스 내부 -이

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
        if (tableView==self.mainTableView) { 
         return titleArray.count; 
        } 
        return timeArray.count; 
    } 
    
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
        if (tableView==self.mainTableView) 
        { 
         MainTableViewCell *cell = [tableView dequeueReusableCellWitentifier:@"cell"]; 
         cell.label.text = [dataArray objectAtIndex:indexPath.row]; 
         return cell; 
        } 
        InnerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 
        cell.view.backgroundColor = [UIColor greenColor]; 
        return cell; 
    } 
    

    내 정의 셀의 설명

    1. 홈페이지 UITableViewCell cusotm 클래스 속성과 같은 데이터 배열을 처리하고 속성 - UIView (예 : myView)

    이제 'myLabel'이 문자열 개체 배열과 일치 할 때 해당 셀에서만 myView를 표시하려고합니다. 예를 들면.

    if([myLabel.text isEqualTostring:@"22"]){ 
    cell.myView.backgroundColor = [UIColor blackColor]; 
    

    } 예를 들어

    . 5 개의 뷰와 2 개의 레이블이있는 경우 이제 UITableView 메인에있는 2 행과 내부에있는 5 행 UITableView하지만 모든 뷰는 myLabel '텍스트와 일치하는 경우에만 외부 셀 에 있어야합니다.

    P.S 일치하는 데이터가 어디에서 오는 지 생각하지 마십시오. 일치하는 데이터의 문제는 아닙니다.

    마지막 결론으로 ​​각 내부 UITableView 셀에 대해 서로 다른 행 수를 생성하려고합니다.

  • +0

    당신이 가지고있는 NSString 속성이있는 myLabel.text가 아니라면 myView를 숨기고 싶습니다. 그렇습니까? –

    +0

    마치 주 테이블에 2 개의 셀이 있고이 두 셀에 3 개의 뷰가 표시되면 이제 뷰가 ​​일치에 따라 나누어집니다. 그러나 일어나고있는 것은 메인 셀 2 개가 두 셀에서 모두 3 개의 뷰를 보여줌으로써 총 6 개의 뷰가됩니다. –

    +0

    이것을 달성하기 위해 어떤 코드를 사용해 보셨습니까? tableView : cellForRowAtIndexPath : 메소드의 코드를 보여 주시겠습니까? –

    답변

    0

    시도해 보셨습니까?

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
        if(tableView == self.mainTableView) 
        { 
         MainTableViewCell *cell = [tableView dequeueReusableCellWitentifier:@"cell"]; 
         cell.label.text = [dataArray objectAtIndex:indexPath.row]; 
         return cell; 
        } 
        InnerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 
    
        MainTableViewCell *parentCell = (MainTableViewCell*)cell.superView; 
        NSIndexPath *parentIndexPath = [self.mainTableView indexPathForCell:parentCell]; 
    
        NSString *text = [dataArray objectAtIndex:parentIndexPath.row]; 
        if([text isEqualTostring:@"22"] //your condition goes here 
        { 
         cell.view.backgroundColor = [UIColor blackColor]; 
        } 
        else 
        { 
         cell.view.backgroundColor = [UIColor greenColor]; 
        } 
    
        return cell; 
    } 
    
    관련 문제