2010-07-30 6 views
0

내 자신의 사용자 정의 셀을 만들려고하는데, 어떤 이유로 그것이 나타나지 않습니다. 나는 많은 예제를 읽었고, 코드는 (적어도 나를 위해) 다른 사람들과 동등한 것처럼 보인다. 인터페이스 빌더를 사용하여 기본보기를 삭제하고, TableViewCell을 추가하고, Identifier = CustomCell을 삽입하고, label을 valueLabel과 연결합니다.아이폰 개발 - 사용자 정의 셀

나를 도와 줄 수 있습니까?

미리 감사드립니다.

//CustomCell.h 
#import <UIKit/UIKit.h> 


@interface CustomCell : UITableViewCell { 
    IBOutlet UILabel *valueLabel; 
} 
@property(nonatomic, retain) IBOutlet UILabel *valueLabel; 

@end 

//CustomCell.C 
#import "CustomCell.h" 
@implementation CustomCell 

@synthesize valueLabel; 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 
    if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { 
     // Initialization code 
    } 
    return self; 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated { 

    [super setSelected:selected animated:animated]; 

    // Configure the view for the selected state 
} 


- (void)dealloc { 
    [super dealloc]; 
} 

@end 


//Where I'm trying to use this cell. Here I imported the .h file (#import "CustomCell.h"): 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"CustomCell"; 

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; 

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

    } 

    cell.valueLabel.text = @"Any text"; 

    return cell; 
} 

답변

0

cellForRowAtIndexPath 메서드가 테이블 뷰 컨트롤러에 속해 있습니까? 그것은 그것이있는 곳입니까?

+0

예, cellForRowAtIndexPath는 다른 파일 (ViewController.C)에 속합니다. – Claudio