【发布时间】:2014-07-29 13:31:11
【问题描述】:
我有 UICollectionView,当我点击集合单元时 UITableView 出现。我想 UITableViewCell 的图像是圆形的,当我第一次加载此表时,所有图像都是圆形的,当我选择并在细节控制器内部移动时,它们仍然是圆形的。但是,当我进入 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;
}
当用户返回第一个视图然后再次切换到 UITableView 时,为什么图像是方形的?
【问题讨论】:
-
将
cell.imageView.clipsToBounds替换为cell.imageView.layer.masksToBounds。 -
它不起作用,甚至警告我“黄色”错误..
-
错误说明了什么?
-
对不起,我错了。没有黄色错误,但有相同的“错误”。首先它是四舍五入的,当我切换到主屏幕并再次进入 tableView 时,它是正方形的。
-
将图层舍入代码放在提交给 SDWebImage 的块之外,圆角半径为 33,因为您知道图像的尺寸。
标签: ios objective-c uitableview