如何在 swift 中按标签来显示/隐藏标签?



如何在 swift 中按标签来显示/隐藏标签?

如何在 SWIFT 中按按钮来显示/隐藏按钮?

如何在 SWIFT 中按单元格来显示/隐藏单元格?

谢谢。

对于按钮:为按钮创建出口操作。在方法类型中: 'yourButton'.isHidden = true

对于标签,将点击手势识别器添加到标签。在它的位置上,键入: 'yourLabel'.isHidden = true

对于细胞,我认为这不是要走的路。最好遵循iOS标准,并通过向左滑动删除该行。喜欢这个:

func tableView(_ tableView: UITableView, commit editingStyle: 
UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
self.tableView.deleteRows(at: [indexPath], with: .automatic)
}
}

UILabel 需要一个手势识别器来处理点击:

let gesture = UITapGestureRecognizer(target: self, action: "handleTap:")
label1.addGestureRecognizer(gesture)
func handleTap(sender: UITapGestureRecognizer) {
if sender.state == .Ended {
label2.isHidden = true
}
}

UIButtons只需要连接到故事板中的IBAction:

@IBAction func buttonPressed(_ object:AnyObject)
{
button2.isHidden = true
}

单元格不能隐藏或显示,必须添加或删除。覆盖:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// add or remove items from data source, then
tableView.reloadData()
}