2014-10-23 3 views
0

UICollectionViewCell (CustomCollectionViewCell)을로드하고 일부 데이터를 전달하고 셀의 레이블이이 데이터로 업데이트되는지 확인해야하는 테스트가 있습니다.단위 테스트에서 UICollectionViewCell 하위 뷰가 업데이트되지 않음

cell.nameLabel은 셀의 UILabel이며 setText 메서드가 호출되지만 텍스트 자체는 업데이트되지 않습니다.

cell.nameLabel.text은 항상 xib에 정의 된 초기 텍스트를 반환합니다. 다음과 같이

레이블이 정의됩니다

@property (nonatomic, weak) IBOutlet UILabel *nameLabel; 

그리고 사양 :

SPEC_BEGIN(CustomCollectionViewCellSpec) 

describe(@"CustomCollectionViewCell", ^{ 

    __block CustomCollectionViewCell *cell = nil; 
    __block CustomCollectionViewCellData *cellData = nil; 

    beforeEach(^{ 

     NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"CustomCollectionViewCell" 
                 owner:self 
                 options:nil]; 

     for (id object in objects) { 

      if ([object isKindOfClass:[CustomCollectionViewCell class]]) { 

       cell = (CustomCollectionViewCell *)object; 

       break; 
      } 
     } 

     cellData = [[CustomCollectionViewCellData alloc] init]; 
     cellData.name = @"Custom name"; 
    }); 

    afterEach(^{ 

     cell = nil; 
     cellData = nil; 
    }); 

    it(@"should populate the views with the cell data", ^{ 

     [[cell.nameLabel should] receive:@selector(setText:) 
          withArguments:cellData.name]; 

     [cell configureWithCellData:cellData]; 

     [[cell.cellData should] equal:cellData]; 

     [[cell.nameLabel.text should] equal:cellData.name]; 
    }); 
}); 

SPEC_END 

답변

0

이 문제는 어떻게 셀을 만드는됩니다. init을 셀에 할당하거나 펜촉을 가져올 수 없습니다. 당신은 컬렉션을 요청합니다. 컬렉션에 대한

당신이 필요합니다

UICollectionView *collection = [[UICollectionView alloc] init]; 
    UICollectionCell *cell = [collection dequeueReusableCellWithReuseIdentifier:@"yourCellIdentifier" forIndexPath:0]; 

이 후, 당신은 당신의 세포를 얻을 수 및 특성 전무 모든 그것의 속성을하지 않고 수정할 수 있습니다.

관련 문제