gpt4 book ai didi

ios - UITableView 单元格方形而不是圆形

转载 作者:行者123 更新时间:2023-12-01 18:13:48 27 4
gpt4 key购买 nike

我有 UICollectionView,当我点击集合单元 UITableView 时出现。我想
UITableViewCell 的图像是圆形的,当我第一次加载此表时,所有图像都是圆形的,当我选择并移入细节 Controller 时,它们仍然是圆形的。但是,当我进入 UITableView(从 UICollectionView 向下),然后按“返回”按钮再次查看 UICollectionView,然后按 UICollectionView 单元格,它会向我显示带有可见“方形(默认)图像”单元格的 UITableView。为什么我说可见?好吧,当我向下滚动时,新的单元格又像它们应该的那样变圆了。为什么会出现这个讨厌的错误?有我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
myCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

UILabel *labelText = (UILabel *)[cell viewWithTag:1000];
labelText.text = [[self.listOfPlaceDetails objectAtIndex:indexPath.row] objectForKey:@"name"];

if (cell == nil){
cell = [[myCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

[cell.imageView setImageWithURL:[NSURL URLWithString:[[self.listOfPlaceDetails objectAtIndex:indexPath.row]objectForKey:@"imageFirst"]] placeholderImage:[UIImage imageNamed:@"noPhoto.png" ]completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType){

UIImage *resizedImage = [image resizedImageWithBounds:CGSizeMake(66, 66)];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

cell.imageView.image = resizedImage;
cell.imageView.layer.cornerRadius = cell.imageView.bounds.size.width /2.0f;
cell.imageView.clipsToBounds = YES;
cell.separatorInset = UIEdgeInsetsMake(0, 82, 0, 0);
}];
self.stringToPass = [[self.listOfPlaceDetails objectAtIndex:indexPath.row]objectForKey:@"description"];

return cell;
}

当用户返回第一个 View 然后再次切换到 UITableView 时,为什么图像是方形的?

最佳答案

我认为问题与此有关:

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

尝试在单元格内设置图像(您使用的是 SDWebImage)吗?
// Set the corner radius and clip to bounds before setting the image
[cell.imageView.layer setCornerRadius:cell.imageView.frame.size.width/2];
cell.imageView.clipToBounds = YES;
// I'm using SDWebImage
[cell.imageView setImageWithURL:[NSURL URLWithString:[[self.listOfPlaceDetails objectAtIndex:indexPath.row]objectForKey:@"imageFirst"]] placeholderImage:[UIImage imageNamed:@"noPhoto.png"]];

希望能帮助到你!

关于ios - UITableView 单元格方形而不是圆形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25016592/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com