我已经创建了如下的UITableViewCell子类。我所做的所有事情都是在单元格的内容视图中添加一个标签并设置其文本。无法继承UITableViewCell
#import <UIKit/UIKit.h>
@interface CustomTableViewCell : UITableViewCell {
}
@end
#import "CustomTableViewCell.h"
@implementation CustomTableViewCell
@synthesize horizontalTableView;
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame]))
{
UIView *myContentView = self.contentView;
UILabel *l = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 30)];
l.text = @"Hi";
[myContentView addSubview:l];
[l release];
}
return self;
}
现在我用这个自定义单元格在我的表视图这样:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"MyCell";
CustomTableViewCell *cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[CustomTableViewCell alloc] initWithFrame:CGRectMake(0, 0, 50, 300) reuseIdentifier:cellIdentifier] autorelease];
}
return cell;
}
但是标签不会在我的表视图显示。我错过了什么?
内部使用NSlog语句,并检查控制是否转到'init'方法。 – Legolas