pojawia się następujący błąd:Dlaczego pojawia się komunikat o błędzie, że nie można usunąć kolejki, gdy mój UITableView próbuje załadować?
* 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'
nie jestem pewien dokładnie to, co robię źle. Ustawiłem identyfikator komórki (programowo, ponieważ nie został on utworzony przez Interface Builder) i robię wszystko, co myślałem, że powinienem robić w metodach delegatów, ale nadal otrzymuję ten błąd, gdy próbuję uzyskać ładowanie UITableView.
Oto odpowiedni kod (warto zauważyć, mam podklasy UITableViewCell dla opcji dostosowywania):
- (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;
}
A oto jedyna metoda Zmieniłem w moim podklasy UITableViewCell (FontCell):
- (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;
}
Co dokładnie robię źle?
Znalazłem ten wątek to ma dobre rozwiązanie: http: // stackoverflow.com/questions/12737860/assertion-failure-in-dequeuereusablecellwithidentifierforindexpath –