[英]No visible @interface for 'UIViewController' declares the selector initWithStyle:reuseIdentifier:
I instantiate a UITableView in a UIViewController when the view is loaded as : 当视图加载为时,我在UIViewController中实例化UITableView:
table = [[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];
The problem is that I want the cell to have style : UITableViewCellStyleValue1. 问题是我希望单元格具有样式:UITableViewCellStyleValue1。 Because the cells are create with the method initWithStyle: UITableViewCellStyleDefault. 因为单元格是使用initWithStyle方法创建的:UITableViewCellStyleDefault。 I can't use dequeueReusableCellWithIdentifier:CellIdentifier. 我不能使用dequeueReusableCellWithIdentifier:CellIdentifier。 My code is thus : 因此,我的代码是:
static NSString *CellIdentifier = @"DetailsFavoris"; 静态NSString * CellIdentifier = @“ DetailsFavoris”;
UITableViewCell *cell ;//= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
...
return cell;
But I would like to reuse the cells to be more efficient. 但是我想重用单元以提高效率。 I wrote down : 我写下:
- (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;
}
But I got an error : No visible @interface for 'UIViewController' declares the selector initWithStyle:reuseIdentifier:. 但是我遇到一个错误:“ UIViewController”没有可见的@interface声明选择器initWithStyle:reuseIdentifier:。
What am I doing wrong? 我究竟做错了什么? I checked on other answers but I found nothing. 我检查了其他答案,但一无所获。
Move this code 移动此代码
- (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;
}
To your UITableViewCell
subclass. 到您的UITableViewCell
子类。 Because this method related to UITableViewCell
class, not to UIViewController
. 因为此方法与UITableViewCell
类相关,所以与UIViewController
不相关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.