Reputation: 3827
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!
Upvotes: 1
Views: 474
Reputation: 9820
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.
Upvotes: 2