【发布时间】:2018-02-17 23:03:36
【问题描述】:
我正在尝试使用 UILabel 和 UIImageView 创建一个表格视图单元格。
这是我的视图控制器打开时的屏幕截图。
当我将单元格滚动出视图或点击单元格时,图像视图的框架会发生变化。
这是我的限制:
这是我的数据源方法:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if(indexPath.section == 0) {
let currentVolume = viewModel.volumes?[indexPath.row];
if let volume = currentVolume {
if (volume.isPurchased == 0) {
let reuseIdentiifier = Constants.ReuseIdentifier.VolumeListTableViewCellReuseId;
let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentiifier, for: indexPath) as! VolumeTableViewCell;
cell.setTitle(title: (volume.name));
return cell;
}
else {
let reuseIdentiifier = Constants.ReuseIdentifier.LockedVolumeListTableViewCellReuseId;
let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentiifier, for: indexPath) as! LockedVolumeTableViewCell;
cell.setTitle(title: (volume.name));
return cell;
}
}
}
return UITableViewCell.init();
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
//Disables the 'selected' cell
tableView.deselectRow(at: indexPath, animated: true);
}
我无法弄清楚出了什么问题?
如果有任何帮助,我将不胜感激。
【问题讨论】:
-
@AamirR 这没有帮助。我还需要在图像视图之前将标题标签的尾随限制为 15 个点。
-
以我的方式使用它有什么问题?理想情况下,我想要的是: 1) trailing = Imageview.trailing + 15 2) label.trailing = imageView.leading - 15 3) imageView.width = 20
-
您的约束看起来不错。这似乎是您的代码中的一个问题。您能否分享您构建和设置单元的代码?
-
@LGP 我已经编辑了帖子以包含我的设置代码。
-
当锁“跳”时,打开查看调试器,看看它是否有任何警告。
标签: ios uitableview autolayout tableview