0

I'm trying to make a pull to refresh on WKWebView. When I try to pull and refresh, I get this error:'NSInvalidArgumentException', reason: '-[GoldenVillage.AvailabilityViewController mymethodforref:]: unrecognized selector sent to instance 0x111d18e50'

How to fix it?

My code in viewDidAppear :

self.availabilityWebview = WKWebView(
     frame: self.containerView.bounds,
     configuration: config
)
self.view = self.availabilityWebview!
refController.bounds = CGRectMake(0, 50, refController.bounds.size.width, refController.bounds.size.height) 
refController.addTarget(self, action: Selector(("mymethodforref:")), for: UIControlEvents.valueChanged)
refController.attributedTitle = NSAttributedString(string: "Pull to refresh")
availabilityWebview?.scrollView.addSubview(refController)

self.noNetwork.text! = ""
if let crew = user!["crew"] as? [String:Any], let crewID = crew["crew_id"] as? String {

let url = URL(string: "http://ec2-52-221-231-3.ap-southeast-1.compute.amazonaws.com/gv/available-schedule_3.php?id=\(crewID)")
self.availabilityWebview!.load(URLRequest(url:url!))


func mymethodforref(refresh:UIRefreshControl){
    availabilityWebview?.reload()
    refController.endRefreshing()
}
func webViewDidFinishLoad(_ webView: UIWebView) {
    UIApplication.shared.isNetworkActivityIndicatorVisible = false
}

func webViewDidStartLoad(_ webView: UIWebView) {
    UIApplication.shared.isNetworkActivityIndicatorVisible = true
}
Lester
  • 701
  • 1
  • 9
  • 47

1 Answers1

1

instead of

Selector(("mymethodforref:")

try

#selector(mymethodforref(refresh:))
3stud1ant3
  • 3,586
  • 2
  • 12
  • 15