【发布时间】:2015-04-06 14:51:47
【问题描述】:
if (indexPath.row == 2)
{
RestaurantTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RestaurantCell"];
if (!cell)
{
[tableView registerNib:[UINib nibWithNibName:@"RestaurantCell" bundle:nil] forCellReuseIdentifier:@"RestaurantCell"];
cell = [tableView dequeueReusableCellWithIdentifier:@"RestaurantCell"];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = cell.gradientView.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor clearColor] CGColor], (id)[[UIColor blackColor]CGColor], nil];
[cell.gradientView.layer insertSublayer:gradient atIndex:0];
cell.gradientView.alpha = 0.9;
}
NSData *imgData2 = [NSData dataWithData:restaurantPhotoArray[1]];
cell.restaurant2Photo.image = [UIImage imageWithData:imgData2];
cell.restaurant2Photo.contentMode = UIViewContentModeScaleAspectFill;
[cell.restaurant2Photo setClipsToBounds:YES];
NSDictionary *morning2 = [[NSDictionary alloc]initWithDictionary:NorthRestaurantsArray[1]];
cell.restaurant2Name.text = morning2[@"name"];
cell.restaurant2Name.numberOfLines = 0;
[cell.restaurant2Name sizeToFit];
}
我有一个自定义单元格,它使用上面的代码在 cellForRowAtIndexPath 中实现。显示表格时,restaurant2Photo 显示指定的图像,并将正确的文本设置为 restaurant2Name,但 sizeToFit 对标签没有影响,因此其大小保持不变,如 .xib 文件中所定义。我有另一个自定义单元格显示在 indexPath 0 和 1 处,其中 sizeToFit 工作正常,但是当它到达 indexPath 2 和 RestaurantTableViewCell sizeToFit 时不起作用。有没有人能提出为什么会发生这种情况?提前感谢您的帮助:)
【问题讨论】:
-
您在 Indexpath 0 和 1 加载的单元格是在 XIB 中构建的?
-
是的,和 indexPath 2 完全一样
-
您是否检查过 contentView 的超级视图有 0 px 的尾边距和 0 px 的下边距?
标签: ios objective-c uitableview