テーブルビューが表示されたら、最初は画像がありません。しかし、ドラッグすると、テーブルビューセルの画像が表示されます。カスタムのtableviewcellクラスを使用しています。テーブルビューセルの画像がすぐに表示されない
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UserCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[UserCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
}
NSLog(@"%d",indexPath.row);
[cell setUser:_chatContent[indexPath.row]];
[cell initUI];
return cell;
}
これは私のカスタムセルクラスです:
- (void)awakeFromNib {
[super awakeFromNib];
}
-(BOOL)initUI{
BOOL isSuccess;
self.userImageView = self.user.userImageView;
UIView *superView = self.contentView;
[superView addSubview:self.userImageView];
[self.userImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(superView.mas_top).with.mas_offset(8);
make.bottom.equalTo(superView.mas_bottom).with.mas_offset(-8);
make.left.equalTo(superView.mas_left).with.mas_offset(8);
make.width.equalTo(superView.mas_height).with.mas_offset(-16);
}];
self.userImageView.layer.cornerRadius = self.userImageView.frame.size.width/2;
self.imageView.clipsToBounds = YES;
isSuccess = YES;
return isSuccess;
}
は最後に、これは私のImageViewのコードです:
のtableViewのリロードので、ImageViewのために画像を設定する前に、セルのimageView.image
nil
への設定
User *user = _chatContent[i];
NSString *fileName = [NSString stringWithFormat:@"%d",i];
NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"jpg"];
user.userImageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:filePath]];
イニシャライザではないメソッドに 'init'を接頭辞として使用してはなりません。 – vikingosegundo
あなたのsuggestion.iに感謝しますit.But私の質問を解決することはできません – RichardSleet
それは私が答えとして投稿していない理由です。 – vikingosegundo