UITATWVIEWCELL IMAVEVIVEVEVEVE未显示
-
13-12-2019 - |
题
所以我有以下代码:
- (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;
}
.
但是,我没有看到单元格中的图像视图。我做错了什么? 解决方案
1)使用URL设置图像不是iOS方法。这是习俗的东西,可能是问题。但直到你发布它无法帮助那里。
2)我认为cell.imageView将忽略“SetFrame”。我无法使用图像在任何桌面单元中工作。它似乎默认为图像的宽度。
3)通常使用cell.imageView.Image= your_Image设置图像。ImageView是ReadOnly,可能是ImageView帧是私有的。
4)我认为您需要创建自己的自定义单元格。
其他提示
我也有sdimageachache的同样的问题。我的解决方案是将占位符图像放在你想要的框架大小。
UIImage *placeholder = [UIImage imageNamed:@"some_image.png"];
[cell.imageView setImage:placeholder];
[cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]];
. 使用占位符的方法将解决它。
[cell.imageView setImageWithURL:[NSURL URLWithString:fd.imageUrl_]placeholderImage:[UIImage imageNamed:@"placeholder"]];
. 您需要在方法结束时生成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;
}
. 不隶属于 StackOverflow