2012-05-22 54 views
6

所以我有下面的代码:的UITableViewCell ImageView的不显示

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSString *CellIdentifier = @"FriendsCell"; 

    FriendData * fd = [self.friendsDataSource_ objectAtIndex:indexPath.row]; 

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 

    [cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]]; 
    [cell.imageView setFrame:CGRectMake(0, 0, 30, 30)]; 
    [cell.textLabel setText:fd.name_]; 

    return cell; 
} 

不过,我没有看到在单元格中的ImageView。我究竟做错了什么?

+1

让我们看看你的-setImageWithURL方法 – shabbirv

+1

随着看到'setImageWithURL:',你确定**'fd.imageUrl_' **不是零? – WrightsCS

+0

是的网址是有效的,不是零 – adit

回答

3

1)设置图像的URL不是iOS的方法结束。这是自定义的,这可能是问题。但是,直到你发布它不能帮助那里。

2)我认为cell.imageView会忽略“setFrame”。我无法在使用图像的任何表格单元格中工作。它总是默认为图像的宽度。

3)通常你使用cell.imageView.image = your_Image设置图像。 ImageView是READONLY,可能ImageView框架是私人的。

4)我认为你将需要创建一个自己的自定义单元格。

2

需要return cell在方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSString *CellIdentifier = @"FriendsCell"; 

    FriendData * fd = [self.friendsDataSource_ objectAtIndex:indexPath.row]; 

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 

    [cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]]; 
    [cell.imageView setFrame:CGRectMake(0, 0, 30, 30)]; 
    [cell.textLabel setText:fd.name_]; 
    return cell; 
} 
+0

我确实做到了..我只是把它切断 – adit

4

我也遇到了与SDImageCache相同的问题。我的解决方案是将一个占位符图像与您想要的帧大小。

UIImage *placeholder = [UIImage imageNamed:@"some_image.png"]; 
[cell.imageView setImage:placeholder]; 
[cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]]; 
3

使用带占位符的方法将修复它。

[cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]placeholderImage:[UIImage imageNamed:@"placeholder"]];