Reputation: 33644
So I had the following code:
- (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;
}
However, I am not seeing the imageView in the cell. What am I doing wrong?
Upvotes: 7
Views: 14642
Reputation: 16664
Usage of a method with placeholder will fix it.
[cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]placeholderImage:[UIImage imageNamed:@"placeholder"]];
Upvotes: 3
Reputation: 5288
I got the same problem with SDImageCache as well. My solution is to put a placeholder image with the frame size you want.
UIImage *placeholder = [UIImage imageNamed:@"some_image.png"];
[cell.imageView setImage:placeholder];
[cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]];
Upvotes: 5
Reputation: 9039
1) Set Image with URL is not an iOS method. It's something custom and that may be the problem. But until you publish it can't help there.
2) I think cell.imageView will ignore "setFrame". I can't get that to work in any of my table cells using an image. It always seems to default to width of the image.
3) Typically you set the image using cell.imageView.image = your_Image. The ImageView is READONLY and probably the ImageView frame is private.
4) I think you are going to need to create a custom cell of your own.
Upvotes: 4
Reputation: 878
you need to return cell
at the end of the method
- (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;
}
Upvotes: 2