Passing arguments to selector in Swift

后端 未结 6 668
闹比i
闹比i 2020-11-27 03:14

I\'m programmatically adding a UITapGestureRecognizer to one of my views:

let gesture = UITapGestureRecognizer(target: self, action: #selector(self.handleTap         


        
6条回答
  •  渐次进展
    2020-11-27 03:48

    that may be a terrible practice but I simply add whatever I want to restore to

    button.restorationIdentifier = urlString

    and

    @objc func openRelatedFact(_ sender: Any) {
            if let button = sender as? UIButton, let stringURL = factButton.restorationIdentifier, let url = URL(string: stringURL) {
                if UIApplication.shared.canOpenURL(url) {
                    UIApplication.shared.open(url, options: [:])
                }
            }
    
        }
    

提交回复
热议问题