gpt4 book ai didi

ios - 在单元格中隐藏按钮

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

我正在开发一个应用程序,用户可以在一个单元格中选择两张图片中的一张。我的原型(prototype)单元看起来像:

enter image description here

我有

cell.rightVoteButton.addTarget(self, action: #selector(voteRightButtonPressed), forControlEvents: .TouchUpInside)

cell.leftVoteButton.addTarget(self, action: #selector(voteLeftButtonPressed), forControlEvents: .TouchUpInside)

tableView 函数中。

func voteRightButtonPressed(sender:UIButton){

print("Right Vote clicked is \(sender.tag)")
print(self.polls[sender.tag].poll_id)

}

通过这种方式,我打印了民意测验 ID 和单元格索引。

我想在单击特定单元格后隐藏投票按钮。例如,如果我单击第一个单元格和左侧图片中的投票,我想隐藏第一个单元格上的两个按钮。我现在是单元格的索引,但如何隐藏特定单元格中的按钮。

我的自定义 TableViewCell:

class CustomTableViewCell: UITableViewCell {

@IBOutlet weak var leftImage: UIImageView!
@IBOutlet weak var rightImage: UIImageView!
@IBOutlet weak var userPicture: UIImageView!
@IBOutlet weak var userName: UILabel!
@IBOutlet weak var leftButton: UIButton!
@IBOutlet weak var rightButton: UIButton!



@IBOutlet weak var pollDescription: UILabel!

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

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

// Configure the view for the selected state
}

}

最佳答案

与其使用没有内在含义且容易混淆的标签,不如这样说:

func voteRightButtonPressed(sender:UIButton){
let location = self.tableView.convertPoint(sender.bounds.origin, fromView:sender)
let indexPath = self.tableView.indexPathForRowAtPoint(location)
if let cell = self.tableView.cellForRowAtIndexPath(indexPath) as? CustomUITableViewCell {

//hide views in cell and update your model to reflect vote.
}
print("Right Vote clicked is \(indexPath.row)")
print(self.polls[indexPath.row].poll_id)

}

一旦你有了单元格,你就可以隐藏你想要的 View ,你可以更新你的模型来反射(reflect)刚刚投的票。

关于ios - 在单元格中隐藏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36754362/

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