UITableViewCell 上的循环 UIImageView 在第一次加载时不起作用

Circular UIImageView on UITableViewCell not working on first load

在我的应用程序的消息部分,我有一个表格视图加载文字和说出消息的用户的图像。我想要图像的圆形图像视图,并且已经编写了代码来做到这一点,但是当我第一次加载它时,可见单元格仍然有一个方形图像。这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell = [self.messagesTable dequeueReusableCellWithIdentifier:@"messageCell"];

    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"messageCell"];

    }

    cell.textLabel.text = [messagesArray objectAtIndex:indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:15.0f];
    cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
    cell.textLabel.numberOfLines = 0;

    cell.imageView.image = [UIImage imageWithData:[[NSUserDefaults standardUserDefaults] objectForKey:@"kUserImageData"]];

    cell.imageView.layer.cornerRadius = cell.imageView.bounds.size.width / 2;
    cell.imageView.clipsToBounds = YES;

    NSLog(@"%f", cell.imageView.bounds.size.height);

   return cell;
}

此外,奇怪的是前几个单元格(具有方形图像)的 NSLog 为 0.000000。我真的不知道我做错了什么。

试试这个代码:

cell.imageView.layer.cornerRadius = cell.imageView.bounds.size.width / 2;

imageView.layer.masksToBounds = YES;

希望这会奏效。