在 InterfaceBuilder 中带有自定义附件视图的 iOS UITableViewCell [英] iOS UITableViewCell with custom accessoryView in InterfaceBuilder

查看:25
本文介绍了在 InterfaceBuilder 中带有自定义附件视图的 iOS UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm creating a settings page for my Swift app and (following examples here on SO) I've subclassed a UITableViewCell and in the init() handlers I've set the accessoryView to be a UISwitch().

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

I also have a custom @IBInspectable property on the subclass which is also marked @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

How can I arrange for the UISwitch to also be visible in InterfaceBuilder so that I can attach additional targets to it whilst still just subclassing from UITableViewCell

理想情况下,我不想用自己的布局创建一个全新的笔尖,因为我仍然希望保留标准 UITableViewCell 的大部分其他功能.

Ideally I don't want to create a whole new nib with its own layout, since I still want to retain most of the other features of a standard UITableViewCell.

推荐答案

Drop UISwitch 到 Interface Builder 的单元内.然后将它与单元格的 accessoryView 连接起来.在标准基本单元格上,控件倾向于锁定在 IB 中的单元格中间.但是在运行时它会被正确定位.

Drop UISwitch in Interface Builder inside of cell. Then wire it with up accessoryView of your cell. On standard basic cells the control tends to be locked in the middle of cell in IB. However in runtime it will be properly positioned.

这篇关于在 InterfaceBuilder 中带有自定义附件视图的 iOS UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆