当视图加载为:
时,我在UIViewController中实例化一个UITableViewtable = [[UITableView alloc]initWithFrame:CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y + hauteurFavorisCell, self.view.frame.size.width, self.view.frame.size.height-hauteurFavorisCell-hauteurNavigationBar)];
[table registerClass:[UITableViewCell class] forCellReuseIdentifier:@"DetailsFavoris"];
table.delegate = self;
table.dataSource = self;
table.hidden = YES;
[self.view addSubview:table];
问题是我希望单元格具有样式:UITableViewCellStyleValue1。因为使用initWithStyle:UITableViewCellStyleDefault方法创建单元格。我不能使用dequeueReusableCellWithIdentifier:CellIdentifier。因此我的代码是:
静态NSString * CellIdentifier = @" DetailsFavoris";
UITableViewCell *cell ;//= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
...
return cell;
但我想重复使用单元格更有效率。我写下来了:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
// ignore the style argument, use our own to override
self = [super initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
if (self) {
// If you need any further customization
}
return self;
}
但是我收到了一个错误:没有可见的@interface用于' UIViewController'声明选择器initWithStyle:reuseIdentifier:。
我做错了什么?我检查了其他答案,但我一无所获。
答案 0 :(得分:1)
移动此代码
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
// ignore the style argument, use our own to override
self = [super initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
if (self) {
// If you need any further customization
}
return self;
}
到您的UITableViewCell
子类。因为此方法与UITableViewCell
类相关,而不是UIViewController
。