gpt4 book ai didi

InterfaceBuilder 中带有自定义 accessoryView 的 iOS UITableViewCell

转载 作者:行者123 更新时间:2023-11-28 11:11:01 25 4
gpt4 key购买 nike

我正在为我的 Swift 应用程序创建一个设置页面,并且(下面是关于 SO 的示例)我已经子类化了一个 UITableViewCell 并且在 init() 处理程序中我已将 accessoryView 设置为 UISwitch()

我在子类上还有一个自定义的 @IBInspectable 属性,它也被标记为 @IBDesignable:

@IBDesignable class TableViewSwitchCell: UITableViewCell {

@IBInspectable var settingsKey: String?

func build()
{
accessoryView = UISwitch()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
build()
}

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
build()
}

// code omitted that uses the settingsKey with NSUserDefaults
}

我如何安排 UISwitch 在 InterfaceBuilder 中也可见,以便我可以将其他目标附加到它,同时仍然只是从 UITableViewCell

继承

理想情况下,我不想创建一个拥有自己布局的全新 nib,因为我仍然想保留标准 UITableViewCell 的大部分其他功能。

最佳答案

UISwitch 放到单元格内的 Interface Builder 中。然后将它与您的单元格的 accessoryView 连接起来。在标准的基本单元格中,控件往往被锁定在 IB 中的单元格中间。但是在运行时它将被正确定位。

关于InterfaceBuilder 中带有自定义 accessoryView 的 iOS UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35088176/

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