使用我的自定义初始化程序初始化我的表格单元格(继承UITableViewCell)

时间:2013-04-30 09:13:12

标签: ios cocoa-touch ios5 uitableview

我创建了自定义表格单元格类:

@interface CommonCell : UITableViewCell{
   ...
}

@end

在其实施文件中,我创建了一个自定义初始化程序方法:initWithCellHeight:reuseIdentifier:showName

调用[super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]),如下所示:

@implementation CommonCell

- (id)initWithCellHeight:(float)cellHeight reuseIdentifier:(NSString *)reuseIdentifier showName:(BOOL)showName
{
    if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier])) {

        [self createViews: showName];
    }
    return self;
}

当我以下列方式在控制器中使用我的单元类时:

#import "CommonCell.h"

...
cell = [[[CommonCell alloc] initWithCellHeight:150 reuseIdentifier:@"CommonCellId" showName:YES] autorelease];

我收到了警告消息:instance method "initWithCellHeight:reuseIdentifier:showName" not found

为什么呢?为什么我不能将自定义初始化程序用于表格单元格?

1 个答案:

答案 0 :(得分:1)

为什么- (id)initWithCellHeight:(float)cellHeight reuseIdentifier:(NSString *)reuseIdentifier showName:(BOOL)showName不存在于头文件中?在使用它来删除警告之前,您需要声明它。