AddTarget:' #selector'的参数并不是指' @ objc'方法,属性或初始化程序

时间:2017-03-15 15:51:44

标签: swift uibutton

我到处寻找答案,但没有一个答案似乎适合我的问题。

我有一个switch语句,只要情况不同就会引用一个函数:

switch wall["ExposureOneType"] as! String {
                case "Twitter":
                cell.exposureButtonOne.addTarget(self, action: #selector(self.openThis(urlStr:"https://twitter.com/\(String(describing: wall["ExposureOne"]))")), for: UIControlEvents.touchUpInside)
                case "Instagram":
                cell.exposureButtonOne.addTarget(self, action: #selector(openThis(urlStr:"https://www.instagram.com/\(String(describing: wall["ExposureOne"]))")), for: UIControlEvents.touchUpInside)
                case "Youtube":
                cell.exposureButtonOne.addTarget(self, action: #selector(openThis(urlStr:"https://www.youtube.com/user/\(String(describing: wall["ExposureOne"]))")), for: UIControlEvents.touchUpInside)
                case "Facebook":
                cell.exposureButtonOne.addTarget(self, action: #selector(openThis(urlStr:"https://www.facebook.com/\(String(describing: wall["ExposureOne"]))")), for: UIControlEvents.touchUpInside)
                case "Snapchat":
                cell.exposureButtonOne.isEnabled = false
            default:
                cell.exposureButtonOne.isEnabled = false
            }

openThis()函数是:

func openThis(urlStr:String!) {

    if let url = URL(string: urlStr) {
        UIApplication.shared.open(url as URL, options: [:], completionHandler: nil)
    }

}

但是我收到了标题中的错误。有什么理由吗?任何解决方法?所有帮助将不胜感激!

0 个答案:

没有答案