2012-10-24 28 views
0

我在故事板中的tableviewcell中遇到了UIImage問題。 當我在tableview中滾動單元格時,它每次都要求服務器發送數據,所以單元格很慢。 我看過這個video ,但它不能在故事板工作,因爲故事板donesn't有UITableViewCell的NIB文件(其集成到故事板)如何將UIImage插入到UITableViewCell中

我在我的項目做什麼

  1. 我創建對象並鏈接到我的插座屬性
  2. 我使用json從互聯網上獲取數據。
  3. 我在桌面上顯示它。

您可以下載我的整個項目文件here。這是代碼在UITableview.m cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"MyCell"; 
    MyCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    // Configure the cell... 
    NSDictionary *entry = [ _entries objectAtIndex:indexPath.row]; 
    cell.boomTitle.text = [entry objectForKey:@"body"]; 
    NSString *imageURL=[NSString stringWithFormat:@"http://kelnakub.co.cc/upload/%i.jpg",[[entry objectForKey:@"IdEntry"] intValue]]; 
    for(NSDictionary *dic in _entries) 
    { 
     NewsFeed *myNewsFeed = [[NewsFeed alloc]init]; 
     myNewsFeed.thumNail = [dic objectForKey:@"IdEntry"]; 
    } 

    NSURL *url = [NSURL URLWithString:imageURL]; 
    NSData *imageData = [NSData dataWithContentsOfURL:url]; 
    cell.boomImage.image = [UIImage imageWithData:imageData]; 
    cell.boomDate.text = [entry objectForKey:@"dateCreated"]; 
    return cell; 
} 

回答

0

您可以用故事板的NIB文件中使用的UITableViewCell。只需使用原型單元格,而不是在Storyboard上設計單元格,就可以創建一個新的NIB並在其上設計UITableViewCell(Storyboard的UITableView保持空單元格)。

然後,在代碼中,您可以使用類似的方式加載單元格:UITableViewCell * MyCustomCell = [[[NSBundle mainBundle] loadNibNamed:@"MyCustomCell" owner:self options:nil] objectAtIndex:1];