0

我在情节提要中的 tableviewcell 中遇到了 UIImage 问题。当我在表格视图中滚动单元格时,它每次都从服务器请求数据,因此单元格非常慢。我看过这个视频 ,但它在情节提要上不起作用,因为情节提要没有 UITableViewCell NIB 文件(它集成到情节提要中)

我在我的项目中做什么

  1. 我创建对象并链接到我的插座属性
  2. 我使用 json 从互联网上获取数据。
  3. 我在tableview上显示它。

你可以在这里下载我的整个项目文件。这是 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;
}
4

1 回答 1

0

您可以使用情节提要在 NIB 文件中使用 UITableViewCell。只需使用原型单元格,而不是在 Storyboard 上设计单元格,而是创建一个新的 NIB 并在其上设计 UITableViewCell(Storyboard 的 UITableView 仍然没有单元格)。

然后,在代码中,您可以使用以下内容加载单元格:UITableViewCell * MyCustomCell = [[[NSBundle mainBundle] loadNibNamed:@"MyCustomCell" owner:self options:nil] objectAtIndex:1];

于 2012-10-24T20:39:43.163 回答