views:

50

answers:

1

Hello all,

I am trying to insert an image into a table cell based off a person search in our company directory. This is pretty easy to do, but the problem is some people do not have pictures so it is throwing their alignment off. Is there any way to have the cell keep that place blank if they don't have a picture, and not slide the text over? This is what my cell construction looks like:

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;
}

Any ideas? Thanks!

+2  A: 

just as a simple design idea: you could put in a default image, ranging from a question mark to just blank space to hold the space.

Jesse Naugher
Ah you know what, that is so simple, but will probably work. Thanks!
gabaum10