第一次没有在iOS 10的tableview中加载图像,而是在滚动之后?

第一次没有在iOS 10的tableview中加载图像,而是在滚动之后?,ios,objective-c,uitableview,ios10,Ios,Objective C,Uitableview,Ios10,我在iOS 10的tableview中显示图像时遇到了问题,但在iOS 10中同样的代码也适用,我在下面添加了代码片段。请帮忙 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifier = @"InboxTableViewCell"; InboxTableViewCell *cell

我在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

在InboxTableViewCell的-voidlayoutSubviews方法中,在设置cornerRadius之前调用[super layoutSubviews]。。您在应用布局之前进行设置,因此[super layoutSubviews]之前的图像帧将为1000,因此您将cornerradius设置为500。 应用自动布局后,图像大小变小,小图像上的500角半径将隐藏图像

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

}

在InboxTableViewCell的-voidlayoutSubviews方法中,在设置cornerRadius之前调用[super layoutSubviews]。。您在应用布局之前进行设置,因此[super layoutSubviews]之前的图像帧将为1000,因此您将cornerradius设置为500。 应用自动布局后,图像大小变小,小图像上的500角半径将隐藏图像

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

}

最后我得到了答案,我现在是我自己的问题了。 我们只需要用drawRect方法编写它,就这样

快乐编码

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

最后我得到了答案,我现在是我自己的问题了。 我们只需要用drawRect方法编写它,就这样

快乐编码

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

下载这个插件到你的项目中,重要的是我也试过了,但不管用,我只是试着设置本地映像。谢谢没有IBOUTLET下载这个插件到你的项目中,重要的是我也试过了,但不管用,我只是试着设置本地映像。谢谢没有IBS出口拐角半径代码有问题吗?我敢打赌,如果你删除它,你的问题仍然会存在,所以我们很可能不需要它来回答。而且,一旦视图从nib中唤醒,就足够了,您不需要重复设置图层属性。dequeueReusableCellWithIdentifier:cellIdentifier永远不会生成nil单元格,那么为什么要检查它呢?LayoutSubview也会被多次调用。因此,相反,在cellForRowAtIndexPath中进行循环。或者在最好的情况下在-awakeFromNib中进行循环。从软件设计的角度来看,视图会自行配置。将其放在viewController中只是一个糟糕的设计。请尝试将您的cell setImage方法放在主队列中。与此分派(异步分派)获取(主)队列类似^void{[cell.profileImageView setImage:[UIImage imagename:@profile.jpg]];};拐角半径代码是问题所在吗?我敢打赌,如果你删除它,你的问题仍然会存在,所以我们很可能不需要它来回答。而且,一旦视图从nib中唤醒,就足够了,您不需要重复设置图层属性。dequeueReusableCellWithIdentifier:cellIdentifier永远不会生成nil单元格,那么为什么要检查它呢?LayoutSubview也会被多次调用。因此,相反,在cellForRowAtIndexPath中进行循环。或者在最好的情况下在-awakeFromNib中进行循环。从软件设计的角度来看,视图会自行配置。将其放在viewController中只是一个糟糕的设计。请尝试将您的cell setImage方法放在主队列中。与此分派(异步分派)获取(主)队列类似^void{[cell.profileImageView setImage:[UIImage imagename:@profile.jpg]];};