2013-06-18 4 views
2

사용자 지정 UIView가 포함 된 IB에서 UITableViewCell을 만들었습니다. 사용자 지정 UIView는 NIB에도 포함되어 있습니다. 이 사용자 지정 UIView를 사용자 지정 UITableViewCell로로드하려면 어떻게해야합니까?NIB에서 UITableViewCell의 하위 클래스 UIView

답변

0

UITableViewCell의 하위 클래스를 만들어야합니다. 하위 클래스의 initWithCoder: 메서드에서 [super initWithCoder:aDecoder]을 호출 한 후 다른 펜촉을로드하고 해당 뷰를 셀의 하위 뷰 (self)로 추가 할 수 있습니다.

+0

내부 - (ID) initWithCoder를 : (NSCoder *) aDecoder는 UITableViewCell의 하위 클래스에서 응용 프로그램이 충돌하고 "캐치되지 않은 예외 'NSUnknownKeyException'으로 인해 응용 프로그램을 종료 함 (이유 : '[ setValue : forUndefinedKey :] :이 클래스는 키 title에 대해 키 값을 코딩하지 않습니다 .Label " – bdev

+0

titleLabel은 셀이로드하려는 사용자 정의 UIView의 라벨입니다. – bdev

+0

질문을 편집하여 전체 충돌의 스택 추적. –

1

여기에서 IB UIView를 사용합니다 (& 1 xib 사용자 정의보기)? 따라서 IB 뷰는 불필요하며 xib는 표시 할 뷰입니다. jQuery과에서

-> 추가 :

[cell getCustomView]; 

얻을 방법을 추가있는 CustomView :

// CustomCell.h 
-(void) getCustomView; 
// CustomCell.h 
-(void) getCustomView{ 
    [customView removeFromSuperview]; 
    customView = [[CustomView alloc] initWithFrame:customView.frame]; 
    [self addSubview:customView]; 
} 

부하 XIB에있는 CustomView 추가

// CustomView.m 
-(id) initWithFrame:(CGRect)frame{ 
    if (self = [super initWithFrame:frame]) { 
     NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:self options:nil]; 
     CustomView *v = (CustomView *)[nibs objectAtIndex:0]; 
     return v; 
    } 
    return self; 
} 
관련 문제