【发布时间】:2017-02-02 04:46:05
【问题描述】:
要求:
我正在做一个sideBar navigation,在里面使用UITableView和UITableViewCell。在UITableViewCell里面,有一个UIImageView和一个UILabel。我希望UIImageView具有相同的height 和 width,我已经给了它限制。
问题:
但是在单击每个单元格后,图像视图的大小会发生变化(缺少约束)并与标签重叠。
我只在情节提要中做了所有约束,我在 swift 3 中做 请帮帮我。
代码工作:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomCell
cell.label.text = data[indexPath.row]
let iconName = images[indexPath.row]
//print("\(iconName)")
let image = UIImage(named: iconName)
// print("The loaded image: \(image)")
cell.imageViews.image = image
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
屏幕截图
【问题讨论】:
-
如果实现了显示你的 didSelectForRow?
-
cell.imageView.maskToBound = true ,试试这个
-
@Himanshu func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true) }
-
为什么要取消选择
didselect方法上的单元格。显示您的原型单元约束。 -
即使我避免取消选择,结果也是一样的--@the_dahiya_boy
标签: ios swift uitableview uiimageview tableviewcell