2010-08-12 37 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