2010-08-12 5 views
1

J'essaie d'insérer une image dans une cellule de table basée sur une recherche de personne dans notre répertoire d'entreprise. C'est assez facile à faire, mais le problème est que certaines personnes n'ont pas d'images, ce qui les déstabilise. Est-il possible de laisser la cellule vide si elle n'a pas d'image et de ne pas faire glisser le texte? Voici à quoi ressemble ma construction cellulaire:Aide sur les cellules de la table personnalisée pour l'iPad

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
} 

Person *aPerson = [appDelegate.people objectAtIndex:indexPath.row]; 

cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", aPerson.first_name, aPerson.last_name]; 
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@, %@, %@", aPerson.sso, aPerson.email, aPerson.business_name]; 


cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 


//trin the newlines out of file url 
NSString *trimmedPath = [aPerson.image_path stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]]; 

if ([trimmedPath length] != 0) { 
    //concat url and retrieve data 
    NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://******.*****.com/%@", trimmedPath]]; 

    NSData *imgData = [NSData dataWithContentsOfURL:url]; 

    //Save into cell 
    UIImage *theImage = [UIImage imageWithData:imgData]; 
    cell.imageView.image = theImage; 
      return cell; 
} else { 
    return cell; 
} 

Des idées? Merci!

Répondre

2

juste comme une idée de conception simple: vous pourriez mettre dans une image par défaut, allant d'un point d'interrogation à un espace vide pour maintenir l'espace.

+0

Ah vous savez quoi, c'est si simple, mais ça marchera probablement. Merci! – gabaum10

Questions connexes