ios - 图像不是第一次加载到 iOS 10 的 tableview 中,而是滚动后?

标签 ios objective-c uitableview ios10

我在 iOS 10 的 tableview 中显示图像时遇到问题,但相同的代码在 iOS 10 下工作,我在下面添加了我的代码片段。请帮忙。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"InboxTableViewCell";

InboxTableViewCell *cell = (InboxTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
    cell = [[InboxTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
[cell setBackgroundColor:[cellColors objectAtIndex:indexPath.row]];
[cell.profileImageView setImage:[UIImage imageNamed:@"profile.jpg"]];

return cell;
}

在单元格中,我将图像制作成圆形

 #import "InboxTableViewCell.h"
@implementation InboxTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];

    // Initialization code


}

-(void)layoutSubviews{
    self.profileImageView.layer.cornerRadius = self.profileImageView.frame.size.width/2;
    self.profileImageView.clipsToBounds=YES;
    [super layoutSubviews];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

最佳答案

终于我得到了答案,现在我是我自己的问题。 我们只需要在 drawRect 方法中编写它就可以了。

快乐编码...

-(void)drawRect:(CGRect)rect
{
    [super drawRect:rect];
    self.profileImageView.layer.cornerRadius=_profileImageView.frame.size.width/2;
    [_profileImageView setClipsToBounds:YES];
    [_profileImageView layoutIfNeeded];
    [_profileImageView setNeedsDisplay];
}

关于ios - 图像不是第一次加载到 iOS 10 的 tableview 中,而是滚动后?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40281936/

相关文章:

ipad - 实现一个类似于 UITableView 出列已创建单元格的方式的系统

iphone - applicationDidBecomeActive 返回首页

iphone - Obj-c,在没有核心数据的情况下,执行许多 SQLite 插入/更新查询的最快方法是什么?

iphone - 谁能告诉我IOS中调用的区别

ios - 移动位于键盘下方的内容

ios - 搜索栏在单击时添加额外的填充

objective-c - 如何调用 Objective C 中的 RefreshTableView 函数?

ios - 在 Parse 后端保存日期和时间

ios - 连接到 SSID 时 Swift 密码短语无效

ios - 在后台接收和响应 EKEventStoreChangedNotification?