ottengo il seguente errore:Perché ricevo un errore relativo all'impossibilità di rimuovere la coda quando il mio UITableView tenta di caricare?
* 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'
io non sono sicuro di quello che sto facendo male. Ho impostato l'identificatore della cella (a livello di codice, poiché non è stato creato tramite Interface Builder) e faccio tutto ciò che pensavo dovessi fare nei metodi delegate, ma sto ancora ricevendo quell'errore quando provo a caricare UITableView.
Ecco il relativo codice (vale la pena notare che ho sottoclasse UITableViewCell per le opzioni di personalizzazione):
- (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;
}
Ed ecco l'unico metodo che ho cambiato nella mia sottoclasse 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;
}
Cosa sto facendo di sbagliato?
ho trovato questa discussione si ha una buona soluzione: http: // StackOverflow.it/questions/12737860/assertion-failure-in-dequeuereusablecellwithidentifier forindexpath –