[英]Tableview not loading when viewcontroller is loaded for the first time
[英]Image not loading in tableview in iOS 10 on first time, but after scroll?
在iOS 10中以表格视图显示图像时出现问题,但在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];
}
在InboxTableViewCell的-(void)layoutSubviews方法中,在设置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;
}
[imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.