gpt4 book ai didi

ios - 一键两个目标

转载 作者:搜寻专家 更新时间:2023-11-01 07:15:03 27 4
gpt4 key购买 nike

我有一个自定义的解开按钮,我也添加了两个目标。如果文本字段为空,则一个目标将起作用,但如果文本字段不为空,则另一个目标将起作用。但是两个目标同时作用于单个按钮。有人可以帮助我并向我解释为什么。

override func viewDidLoad() {
super.viewDidLoad()
FirstName.delegate = self
LastName.delegate = self
FirstName.addTarget(self, action:"edited", for:UIControlEvents.allEditingEvents)
LastName.addTarget(self, action:"edited", for:UIControlEvents.allEditingEvents)
// Do any additional setup after loading the view.
if FirstName.text?.isEmpty == true || LastName.text == "" {
ProgressButton.setImage(UIImage(named: "Skip"), for: .normal)
ProgressButton.contentEdgeInsets = UIEdgeInsetsMake(0,0,0,0)
ProgressButton.addTarget(self, action: #selector(Skip(_sender:)), for: UIControlEvents.touchUpInside)
} else {
ProgressButton.setImage(UIImage(named: "Right2"), for: .normal)
ProgressButton.contentEdgeInsets = UIEdgeInsetsMake(20,31,24,0)
ProgressButton.addTarget(self, action: #selector(Continue(_sender:)), for: UIControlEvents.touchUpInside)
}
}

func edited() {
if FirstName.text?.isEmpty == true || LastName.text == "" {
ProgressButton.setImage(UIImage(named: "Skip"), for: .normal)
ProgressButton.contentEdgeInsets = UIEdgeInsetsMake(0,0,0,0)
ProgressButton.addTarget(self, action: #selector(Skip(_sender:)), for: UIControlEvents.touchUpInside)
} else {
ProgressButton.setImage(UIImage(named: "Right2"), for: .normal)
ProgressButton.contentEdgeInsets = UIEdgeInsetsMake(20,31,24,0)
ProgressButton.addTarget(self, action: #selector(Continue(_sender:)), for: UIControlEvents.touchUpInside)
}
}

func Continue(_sender: ABProgressButton!) {
FirstName.resignFirstResponder()
LastName.resignFirstResponder()
// Delay the dismissal by 5 seconds
let delay = 0.85 * Double(NSEC_PER_SEC)
var time = DispatchTime.now() + Double(Int64(delay)) / Double(NSEC_PER_SEC)
DispatchQueue.main.asyncAfter(deadline: time, execute: {

self.performSegue(withIdentifier: "ToViewController#2", sender: nil)

})

}

func Skip(_sender: ABProgressButton!) {
FirstName.resignFirstResponder()
LastName.resignFirstResponder()
self.performSegue(withIdentifier: "ToViewController#2", sender: nil)
}

最佳答案

您需要为已安装在按钮上的操作调用 removeTarget(_:action:for:)。检查 addTarget(_:action:for:) header 中的注释。

关于ios - 一键两个目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42568640/

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