我在里面用UIView创建了一个自定义调用。我认为到目前为止,通过发送URL(尚未对其进行测试,只是判断),我得到的一切正确,但我的问题是设置WKWebView。我只是不确定如何从文件中调用UIView,然后在内部设置WKWebView" DidSelect MKAnnotationView"。这就是我的问题,在内部调用UIView" DidSelect"并将其设置为WKWebView。
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
if view.annotation is MKUserLocation { return }
let customAnnotation = view.annotation as! CustomBusinessPoint
let views = Bundle.main.loadNibNamed("CustomBusinessCallOut", owner: nil, options: nil)
let calloutView = views?[0] as! CustomBusinessCallOut
calloutView.goToProfile.addTarget(self, action:#selector(handleRegister(sender:)), for: .touchUpInside)
calloutView.browserView.addSubview(webview!)
calloutView.websiteURL.addTarget(self, action:#selector(businessWebsite(sender:)), for: .touchUpInside)
calloutView.facebookURL.addTarget(self, action:#selector(businessFacebook(sender:)), for: .touchUpInside)
calloutView.twitterURL.addTarget(self, action:#selector(businessTwitter(sender:)), for: .touchUpInside)
calloutView.instagramURL.addTarget(self, action:#selector(businessInstagram(sender:)), for: .touchUpInside)
calloutView.googleURL.addTarget(self, action:#selector(businessGoogle(sender:)), for: .touchUpInside)
calloutView.yelpURL.addTarget(self, action:#selector(businessYelp(sender:)), for: .touchUpInside)
calloutView.foursquareURL.addTarget(self, action:#selector(businessFoursquare(sender:)), for: .touchUpInside)
calloutView.snapchatURL.addTarget(self, action:#selector(businessSnapchat(sender:)), for: .touchUpInside)
calloutView.businessName.text = customAnnotation.businessName
calloutView.center = CGPoint(x: view.bounds.size.width / 2, y: -calloutView.bounds.size.height * -0.0001)
view.addSubview(calloutView)
mapView.setCenter((view.annotation?.coordinate)!, animated: true)
}
func businessWebsite(sender: UIButton) {
if let dictionary = locationData! as? [String: AnyObject],
let businessWebsite = dictionary["businessWebsite"] as? String,
let url = NSURL(string: businessWebsite) {
let request = NSURLRequest(url: url as URL)
self.webView?.load(request as URLRequest)
} else {
print("No value")
DispatchQueue.main.async(execute: {() -> Void in
CommonUtils.sharedUtils.hideProgress()
CommonUtils.sharedUtils.showAlert(self, title: "Ooops!", message: "This location does not have a website")
})
}
}