【发布时间】:2017-02-07 15:41:51
【问题描述】:
我在多个 VC 中有一个呼叫按钮,它执行呼叫同一号码的操作。我决定创建 UIButton 的扩展,而不是在每个 VC 中定义相同的函数。
需要帮助,不知道为什么我遇到问题,但在 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 '
【问题讨论】:
-
你是如何调用这个方法的!
-
实际上我添加了 3 个参数目标、动作和控制。打算打电话给
btn.addTarget(btn.callBtn) -
@Vishnuvardhan :- 以下是我调用该方法的方式:-
callBtn.addTarget(self, action: #selector(callBtn.callBtn(_:)), forControlEvents: .TouchUpInside)在所需的 VC 中 -
@EricAya 那是我的真实密码,只是手机号码变了。