【问题标题】:How to setup Detail Accessory Type in Custom Cell如何在自定义单元格中设置详细配件类型
【发布时间】:2015-09-27 17:45:21
【问题描述】:

我的桌子上的每个单元格都有自定义单元格类。我为每个单元格添加了详细配件类型。我希望用户单击详细配件类型(其中带有 i 的蓝色圆圈),然后弹出窗口应显示有关该特定单元格的更多信息。我用谷歌搜索并没有找到详细配件类型的解决方案。

以下是我的第一个单元格的自定义类。

class SocialTableCell: UITableViewCell {

@IBOutlet weak var social:UILabel?  
@IBOutlet weak var toggle:UISwitch?

override func awakeFromNib() {
    super.awakeFromNib()
}
override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
}
}

任何帮助将不胜感激。 谢谢

【问题讨论】:

    标签: ios swift uitableview accessorytype


    【解决方案1】:

    UITableViewDelegate 协议有一个 tableView:accessoryButtonTappedForRowWithIndexPath: 方法,当用户点击其中一个单元格中的附件按钮时会调用该方法。所以你必须在你的 TableViewController 中实现那个方法:

    func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath) {
       // show the alert here
    }
    

    您还必须确保将 UITableView.delegate 设置为实现该方法的 ViewController。

    【讨论】:

    • Swift 5.1 使用IndexPath 而不是NSIndexPath
    猜你喜欢
    • 1970-01-01
    • 2015-07-06
    • 1970-01-01
    • 1970-01-01
    • 2018-01-11
    • 2020-04-17
    • 1970-01-01
    • 2018-09-07
    • 1970-01-01
    相关资源
    最近更新 更多