0

J'ai créé un UITableViewCell personnalisé à partir d'un NIB. Tout apparaît lorsque le rowHeight n'est pas défini (bien que tout soit écrasé). Je ne sais pas si je suis réutilisez et de créer les cellules correctement:UITableViewCell n'apparaît pas/ne se réutilise pas correctement depuis NIB

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *MyIdentifier = @"ARCell"; 
    ARObject *myARObject; 
    myARObject = [items objectAtIndex:indexPath.row]; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
    if (cell == nil) { 
     [[NSBundle mainBundle] loadNibNamed:@"ARCell" owner:self options:nil]; 
     cell = arCell; 
     self.arCell = nil; 
    } 

    UILabel *label; 
    label = (UILabel *)[cell viewWithTag:0]; 
    label.text = [NSString stringWithFormat:@"%@", myARObject.username]; 

    label = (UILabel *)[cell viewWithTag:1]; 
    label.text = [NSString stringWithFormat:@"%@", myARObject.created_at]; 

    label = (UILabel *)[cell viewWithTag:2]; 
    label.text = [NSString stringWithFormat:@"%@", myARObject.articleTitle]; 

    label = (UILabel *)[cell viewWithTag:3]; 
    label.text = [NSString stringWithFormat:@"%@", myARObject.intro_text]; 

    return cell; 
} 

- (CGFloat)tableView:(UITableView *)tblView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ CGFloat rowHeight = 105; 
    return rowHeight; 
} 

Problèmes:

  1. Toutes les étiquettes apparaissent lorsque rowHeight est réglé. Si rowHeight n'est pas défini, les étiquettes sont écrasées
  2. Lorsque rowHeight n'est pas défini, la sélection d'un élément indique toutes les étiquettes

Répondre

0

Retirez la clause else

+0

existe toujours –

0

Vous appelez loadNibNamed, mais ne pas stocker résultat n'importe où! Je ne comprends pas pourquoi votre code fonctionne tout ... Quoi qu'il en soit, aveugle écrit que je voudrais essayer quelque chose comme ceci: problème

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *MyIdentifier = @"ARCell"; 
    ARObject *myARObject = [items objectAtIndex:indexPath.row]; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
    if (cell == nil) { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ARCell" owner:self options:nil]; 
     cell = (UITableViewCell *)[nib objectAtIndex:0]; 
    } 

    UILabel *label; 
    label = (UILabel *)[cell viewWithTag:0]; 
    label.text = [NSString stringWithFormat:@"%@", myARObject.username]; 

    label = (UILabel *)[cell viewWithTag:1]; 
    label.text = [NSString stringWithFormat:@"%@", myARObject.created_at]; 

    label = (UILabel *)[cell viewWithTag:2]; 
    label.text = [NSString stringWithFormat:@"%@", myARObject.articleTitle]; 

    label = (UILabel *)[cell viewWithTag:3]; 
    label.text = [NSString stringWithFormat:@"%@", myARObject.intro_text]; 

    return cell; 
} 

- (CGFloat)tableView:(UITableView *)tblView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 105.0; 
} 
+0

i obtenir le même résultat. au lieu de cell = (UITableViewCell *) [nib objectAtIndex: 0]; Je l'attribue à arCell qui est une propriété UITableViewCell dans mon fichier h –

+0

Je suis l'exemple du Guide de programmation Apple TableView: http://developer.apple.com/iphone/library/documentation/userexperience/conceptual/TableView_iPhone/ TableViewCells/TableViewCells.html # // apple_ref/doc/uid/TP40007451-CH7-SW1 –

+0

Vérifié et l'exemple ressemble à votre code. Ensuite, vérifiez votre arCell IBOutlet "en raison de la connexion de sortie que vous avez faite, la sortie tvCell a maintenant une référence à la cellule chargée à partir du fichier nib." – JOM

Questions connexes