我在多个 VC 中有一个调用按钮,它执行调用相同号码的操作。我没有在每个 VC 中定义相同的函数,而是决定创建 UIButton 的扩展。
需要帮助,不知道为什么我会遇到问题,但在 target:self
处出错,说 Expected parameter type following ':'
代码如下:-
extension UIButton {
func callBtn(target:self)
{
let url = NSURL(string: "tel://1234567890")!
UIApplication.sharedApplication().openURL(url)
}
}
编辑: 更新到提到的解决方案:-
extension UIButton {
func callBtn(target:UIButton)
{
let url = NSURL(string: "tel://1234567890)")!
UIApplication.sharedApplication().openURL(url)
}
}
Inside Required VCs :- (调用如下)
callBtn.addTarget(self, action: #selector(callBtn.callBtn(_:)), forControlEvents: .TouchUpInside)
出现以下错误:-
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- unrecognized selector sent to instance 0x15e8b330 '
最佳答案
你的代码应该是这样的,
extension UIButton {
func callBtn(target:UIButton)
{
let url = NSURL(string: "tel://1234567890")!
UIApplication.sharedApplication().openURL(url)
}
}
关于ios - UIButton 扩展的实现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39768177/