2013-07-25 40 views
0

從來就一直在尋找通過大量的代碼在這裏,但沒有很長的時間幫我....定製TableViewCell不叫(編程)

我創建了一個自定義的編程TableViewCell,我想將它們與連接另一種觀點。這是我的代碼。

.h文件

// GTCustomCellView.h 
#import "GTView.h" 
@interface GTCustomCellView : UITableViewCell 
@property (nonatomic, retain) GTView* containerView; 
@property (nonatomic, retain) GTImageView* commentImageView; 
@property (nonatomic, retain) GTTextView* commentView; 
@property (nonatomic, retain) GTTextView* dateView; 
@property (nonatomic, retain) GTTextView* authorView; 
@property (nonatomic, retain) GTView* groupView; 
@property (nonatomic, retain) UILabel* mainView; 

@end 

.m文件

@implementation GTCustomCellView 


- (id)initWithFrame:(CGRect)frame { 
self = [super initWithFrame:frame]; 
if (self) { 

    self.layout = [[[GTFlowLayout alloc] initWithSpacing: 0] autorelease]; 
    self.backgroundColor = GTDefaultBackgroundColor; 


    self.containerView = [[[GTView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.frame.size.width, 100.0f)]autorelease]; 
    [self.contentView addSubview:self.containerView]; 


    self.commentImageView = [[[GTImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 70.0f, 70.0f)] autorelease]; 
    [self.containerView addSubview:self.commentImageView]; 


    self.groupView =[[[GTView alloc] initWithFrame:CGRectMake(70.0, 0.0, self.frame.size.width - self.commentImageView.frame.size.width, self.containerView.frame.size.height)]autorelease]; 
    [self.containerView addSubview: self.groupView]; 


    self.authorView = [[[GTTextView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.frame.size.width, 20.0f)]autorelease]; 
    [self.groupView addSubview:self.authorView]; 

    self.dateView = [[[GTTextView alloc] initWithFrame:CGRectMake(0.0, 20.0, self.frame.size.width, 20.0f)]autorelease]; 
    [self.groupView addSubview:self.dateView]; 

    self.commentView = [[[GTTextView alloc] initWithFrame:CGRectMake(0.0, 40.0, self.frame.size.width, 60.0f)]autorelease]; 
    [self.groupView addSubview:self.commentView]; 


} 
return self; 
} 

這裏是其它視圖的重要組成部分:

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

static NSString *CellIdentifier = @"Cell"; 

GTCustomCellView *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[GTCustomCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 


cell.authorView.text = @"Author Test"; 
cell.dateView.text = @"Date Test"; 
cell.commentView.text = @"Comment test"; 


return cell; 
} 

我只得到空單元格,我唯一的想法是我使用Views而不是UILabels?

+1

如果你打電話'initWithStyle'創建的細胞表視圖控制器,那麼你應該在單元類中實現* that *方法,而不是'initWithFrame'。 –

+0

謝謝,它現在有效:D – Davis

回答

0

你有沒有設置委託和表視圖的數據源:

yourTableView.delegate = self; 
yourTableView.dataSource = self; 

你應該在你的視圖控制器做到這一點。