私は次のエラーを取得する:UITableViewがロードしようとしたときにデキューできないというエラーが表示されるのはなぜですか?
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier FontCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
は私が間違ってやっている正確に何かわかりません。私はセルの識別子を設定しています(プログラムでは、Interface Builderで作成されていないので)、デリゲートメソッドでやろうと思ったことはすべて実行しますが、UITableViewをロードしようとすると、
ここでは、関連するコード(それは私がカスタマイズオプションのためのUITableViewCellのサブクラス化しまし注目に値します)です:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.fontFamilyLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 200, 20)];
self.fontFamilyLabel.textAlignment = NSTextAlignmentCenter;
[self.contentView addSubview:self.fontFamilyLabel];
}
return self;
}
:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.fonts.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"FontCell";
FontCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if (!cell) {
cell = [[FontCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FontCell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
int row = indexPath.row;
cell.fontFamilyLabel.text = self.fonts[row];
return cell;
}
そして、ここでは、私は私のサブクラスのUITableViewCell(FontCell)に変更唯一の方法だが、
私は間違って何をしていますか?
Identitifierを設定し、私はこのスレッドにそれを発見しました良い解決策があります:http:// stackoverflow。com/questions/12737860 /アサーション - デキュー可能なセルとインデックスパスを区別する –