2012-08-13 2 views
0

안녕하세요, 저는 UITableViewCell을 사용자 지정해야합니다. 그래서 나는 그것을 지원하기 위해 커스텀 클래스와 필요한 UI (xib)를 만들었다. XIB의 경우 클래스를 내가 만든 파생 클래스로 선택했습니다. 내 문제는 표시 레이블을 속성에 연결 한 후 런타임에 값을 설정해도 원하는 텍스트가 표시되지 않는 경우입니다. 그것의 공백으로 왼쪽. 아래는 코드 스 니펫입니다. 먼저ios TableViewCell 사용자 지정 문제입니다. 사용자 지정 텍스트 표시 안 함

@interface CustomCell : UITableViewCell 
{ 
    IBOutlet UILabel *titleRow; 
} 

@property (nonatomic, strong) UILabel *titleRow; 
@property (nonatomic, strong) UILabel *subTitleRow; 
@property (nonatomic, strong) UILabel *otherTextRow; 
@end 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"MedVaultCell"; 
    CustomCell *cell = nil; 
    cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    // Configure the cell... 
    if (nil == cell){ 

     //Load custom cell from NIB file 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCellHistoryCell" owner:self options:NULL]; 
     cell = [nib objectAtIndex:0]; 

     //cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 

     //cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 
    } 

    // get the object 
    Weight *currentCellWeight = [_weights objectAtIndex:indexPath.row]; 

    // Configure the cell... 
    UILabel *titleLable = [[UILabel alloc]init]; 
    titleLable.text = currentCellWeight.customDispText; 
    [cell setTitleRow:titleLable]; 

    cell.titleRow.text = currentCellWeight.display; 
    cell.titleRow.textColor = [UIColor redColor]; 
    //cell.textLabel.text = [[_weights objectAtIndex:indexPath.row] customDispText]; 
    //cell.textLabel.textColor = [UIColor whiteColor]; 


    return cell; 
} 
+0

사용자 정의 셀 클래스에'cellForRowAtIndexPath'를 넣고 있습니까? –

답변

0

, 나는 당신의 cellForRowAtIndexPath가 아닌 사용자 정의 셀 클래스에서, 당신의 UITableViewdelegate에 바랍니다. 이 코드에서

// Configure the cell... 
UILabel *titleLable = [[UILabel alloc]init]; 
titleLable.text = currentCellWeight.customDispText; 
[cell setTitleRow:titleLable]; 

새 레이블을 만들고 새 레이블로 함께 IBOutlet 라벨을 재정의 :

둘째, 여기에 문제가 있습니다. 그런 다음 새 레이블을 표시하지 않습니다. 대신,이에 코드를 변경합니다

// Configure the cell... 
cell.titleRow.text = currentCellWeight.customDispText; 

그러나 다음 currentCellWeight.display에 바로 후 titleRow.text를 재설정합니다.

그래서 당신은 텍스트가되고 싶은 텍스트를 골라야합니다. 이미 IB에서 레이블을 작성 했으므로 새 레이블 (UILabel *titleLable = [[UILabel alloc] init];)을 작성할 필요가 없습니다.

+0

코드를 가지고 노는 것에 대해 사과하고 싶지 않아서 죄송합니다. 아웃. 방금 당신이 제안한 것과 같은 변화를 만들었지 만 여전히 효과가 없었습니다. 기본 설정을 시도하면 무엇이 작동합니까? cell.textLabel.text = currentCellWeight.display; 그러나 이것은 내가 원하는 방식으로 셀을 사용자 지정할 수 없다는 것을 의미합니다. – user959671

+0

셀 식별자가 "MedVaultCell"로 설정되고 셀의 클래스가 "CustomCell"로 설정되어 있고 IBOutlet이 제대로 연결되어 있는지 확인하십시오. –

+0

차가움. 그게 도움이. 고맙습니다 저스틴! – user959671

관련 문제