2014-04-05 2 views
0

나는 프로토 타입 셀을 기존 테이블 뷰로 드래그해야하는 새 프로젝트를 가지고 있습니다.빈 프로토 타입 셀

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"myCustomCell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
// Configure the cell... 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 
UILabel *nameLabel = (UILabel *)[cell viewWithTag:11]; 
: 그때

이 다음 내있는 tableview 위임에 내가 대리인 콜백을 얻을 셀에 대한 식별자를 설정 적절한 태그 프로토 타입 셀에 일부 레이블을 추가

그 이름이 표시됩니다. 라벨은 무효입니다. 두 번 확인하고 세 번 반복 태그와 재사용이 가능한 식별자를 확인했습니다. 스토리 보드에서, 나는 tableview가 내 라벨을 보여주는 contentView와 함께 그 셀로 프로 타입 셀을 가지고 있다는 것을 알았다. 내가 뭘 놓치고 있니?

답변

0

분기가 if (cell == nil) 인 새 셀을 만들었습니까? 그렇다면 일반 UITAbleViewCell을 만듭니다. nib 파일이나 스토리 보드에서로드하지 않기 때문에 사용자 정의 lable을 기대하지 마십시오.

셀 객체는 어떤 유형입니까? 그것을 NSLog하거나 실제로 어떤 유형이 만들어 졌는지 디버거에서 확인하십시오.

0

사용자 지정 레이블이 포함되지 않은 UITableViewCell을 할당하고 있습니다. 스토리 보드를 사용하여 뷰를 만든 경우 다음 방법을 사용하여 뷰를 할당해야합니다.

당신은 희망이 당신을 도울 것입니다

CustomViewCell *cell = (CustomViewCell *)[tableView dequeueReusableCellWithIdentifier:@"CustomViewCell"]; 
if (cell == nil) 
{ 
    cell = [Utility loadNibNamed:@"CustomViewCell" ofClass:[CustomViewCell class]]; 
} 

cell.yourLabel.text = @"Dummy Text"; 

같은 코드에서 사용

+ (id)loadNibNamed:(NSString *)nibName ofClass:(Class)objClass 
{ 
    if (nibName && objClass) 
    { 
     NSArray *objects = [[NSBundle mainBundle] loadNibNamed:nibName 
                owner:nil 
                options:nil];    
     for (id currentObject in objects) 
     { 
      if ([currentObject isKindOfClass:objClass]) 
       return currentObject; 
     } 
    } 
    return nil; 
} 

NibName

에서이 클래스의 인스턴스를 얻을 수있는 유틸리티 방법을 만들 수 있습니다.