我创建了自定义表格单元格类:
@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
为什么呢?为什么我不能将自定义初始化程序用于表格单元格?
答案 0 :(得分:1)
为什么- (id)initWithCellHeight:(float)cellHeight reuseIdentifier:(NSString *)reuseIdentifier showName:(BOOL)showName
不存在于头文件中?在使用它来删除警告之前,您需要声明它。