J'ai créé une application très simple où j'essaie d'insérer une cellule personnalisée dans une vue de table. Cependant, chaque fois que je retourne une instance de la cellule personnalisée, un rien est affiché sur l'écran et en second lieu, l'application entre dans une sorte de boucle infinie étrange. Toute aide serait très appréciée. J'ai joint mon code dans cette question.Création de cellule personnalisée prend l'application iphone dans une boucle infinie
-- view controller which is returning custom cells ---
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Try to recover a cell from the table view with the given identifier, this is for performance
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
// If no cell is available, create a new one using the given identifier
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle]
loadNibNamed:@"sample_1ViewController" owner:self options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[CustomCell class]])
{
cell = currentObject;
break;
}
}
}
// Fill the cell
cell.lbl.text = @"test";
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 4;
}
--- custom cell class ---
@interface CustomCell : UITableViewCell {
IBOutlet UILabel * lbl;
}
@property (nonatomic, retain) IBOutlet UILabel * lbl;
@end
@implementation CustomCell
@synthesize lbl;
@end
----
La cellule personnalisée est une ressource UITableCellView dans le fichier sample_1ViewController.xib. Il contient un UILabel. L'identifiant de CustomCell est également CustomCell.
S'il vous plaît voir si vous pourriez trouver quelque chose qui pourrait être faux ou me parler de quelque chose qui me manque peut-être.
Cordialement Nitin
Sur quoi est la trace de la pile de la boucle infinie? – gcamp