2010-08-12 61 views
1

我正尝试将图像插入基于我们公司目录中的人员搜索的表格单元格中。这很容易做到,但问题是有些人没有照片,所以他们就会抛弃他们的关系。如果没有图片,有没有办法让单元格保持空白,并且不会将文本滑过?这是我的细胞结构看起来像: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; 
} 

任何想法?谢谢!

回答

2

就像一个简单的设计理念:您可以放置​​一个默认图像,从问号到空白空间以保存空间。

+0

啊,你知道什么,这是如此简单,但可能会工作。谢谢! – gabaum10 2010-08-12 19:13:25