【发布时间】:2016-09-08 16:17:48
【问题描述】:
我正在构建一个动态表格视图单元格。高度根据加载的内容是动态的。我遇到了图像视图高度的挂断。当前加载的图像填充宽度为 100% 的图像视图。如果表格视图单元格没有图像,是否可以在我的图像视图上设置自动布局约束,以便隐藏图像视图(高度为 0)?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TableViewTileCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tileCell"];
if (!cell)
{
[tableView registerNib:[UINib nibWithNibName:@"TableViewTileCell" bundle:nil] forCellReuseIdentifier:@"tileCell"];
cell = [tableView dequeueReusableCellWithIdentifier:@"tileCell"];
}
cell.tileView.layer.borderColor = [UIColor blackColor].CGColor;
cell.tileView.layer.borderWidth = 1.0f;
[cell.contentView setBackgroundColor:[UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.0]];
NSString *url=[self.resultsArray[indexPath.row] valueForKey:@"imageURL"];
cell.tileTitle.text = [self.resultsArray[indexPath.row] valueForKey:@"title"];
cell.tileDate.text = [self.resultsArray[indexPath.row] valueForKey:@"date"];
cell.tileContent.text = [self.resultsArray[indexPath.row] valueForKey:@"summary"];
if(![url isEqualToString:@""]){ //If we got a url value back load the image
[cell.tileImageview setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
}
return cell;
}
【问题讨论】:
-
你能发布你的
cellForRowAtIndexPath吗?
标签: ios uitableview uiimageview autolayout