我在这里搜索了很多代码,但没有任何帮助......
我以编程方式创建了一个自定义 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;
}
我只得到空单元格,我唯一的想法是我使用视图而不是 UILabels?