gpt4 book ai didi

swift - 分配给类型为 `UIView` 的属性无效

转载 作者:行者123 更新时间:2023-11-28 14:15:33 29 4
gpt4 key购买 nike

我使用的是 Xcode 10.0 beta 6,所以这可能只是一个错误。


我遇到了一个问题,将新的 UIView 实例分配给一个属性,似乎对该属性没有任何影响。

ViewTextFieldCell中的leadingView属性:

class ViewTextFieldCell: UITableViewCell {

// ...

var leadingView = UIView()

// ...
}

当以下列方式修改单元格实例时...

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = ViewTextFieldCell(style: .default, reuseIdentifier: "TestCell")

cell.leadingView.backgroundColor = .blue

let otherView = UIView()
otherView.backgroundColor = .green
cell.leadingView = otherView

return cell
}

...唯一保留的变化是将背景颜色设置为蓝色。
看来otherView的赋值没有效果。

这怎么可能?

最佳答案

从您的示例中不清楚“leadingView”发生了哪些其他初始化,但是替换“otherView”没有作为 subview 添加到单元格,也没有框架或约束。

关于swift - 分配给类型为 `UIView` 的属性无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52210386/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com