所以我有此按钮的功能代码
@objc func facebookButtonPressed(_ urlString : String)
{
let url = URL(string: urlString)!;
let safariViewController = SFSafariViewController(url: url);
self.present(safariViewController, animated: true,completion: nil);
}
并将此功能直接附加到我的按钮
cell.facebookButton.addTarget(cell.facebookButton, action: #selector(facebookButtonPressed(_:facebookHandles[0])), for: UIControlEvents.touchUpInside);
facebookHandles看起来像这样:
let facebookHandles = ["https://www.facebook.com/harsh.mutha.902","https://www.facebook.com/skvrahul?fb_dtsg_ag=AdzxdqYcNvlFjd6QcX6a2sTXKagTQsR_OCuyHLe8z8gPug%3AAdxQz3YDUQ3tL-a7ME_0Owzu-02FSL0SO7VWqcJ_CpPUrw","https://www.facebook.com/saptarshi.roychaudhuri?fb_dtsg_ag=AdzxdqYcNvlFjd6QcX6a2sTXKagTQsR_OCuyHLe8z8gPug%3AAdxQz3YDUQ3tL-a7ME_0Owzu-02FSL0SO7VWqcJ_CpPUrw"];
为什么会出现此错误,我该如何解决?
Argument of '#selector' does not refer to an '@objc' method, property, or initializer
collection view where the buttons are
从图像中可以看到,在集合视图中每个单元都有多个按钮。 现在,当单击开发者单元格的Facebook按钮时,如何为开发者适当打开Facebook页面?
答案 0 :(得分:0)
您无法将类型UIButton
的参数更改为String
,可能需要在cellForItemAt
内
cell.facebookButton.addTarget(self, action: #selector(facebookButtonPressed(_:)), for: UIControlEvents.touchUpInside)
cell.facebookButton.tag = indexPath.row
在vc工具中
@objc func facebookButtonPressed(_ sender: UIButton) {
print(facebookHandles[sender.tag])
let url = URL(string: facebookHandles[sender.tag])!
let safariViewController = SFSafariViewController(url: url)
self.present(safariViewController, animated: true,completion: nil)
}