Back Button on UIWebView

余生颓废 提交于 2019-12-05 02:17:10

actionSheet:clickedButtonAtIndex: is for UIActionSheet objects, not UIButton actions.

You should probably write an IBAction method that looks something like this:

- (IBAction)backButtonTapped:(id)sender {
   [_viewWeb goBack];
}

and connect it to the Touch Up Inside action from the button.

You can search for more info on IBAction but that's likely what you want

I think it should be more specific like this

- (IBAction)backButtonTapped:(id)sender {
   if ([_viewWeb canGoBack] ) {
       [_viewWeb goBack];
   }
}

I have struggled to get a working code for this function written in swift and finally here's what i came up with.

 @IBOutlet weak var goBackBtn: UIBarButtonItem!
 @IBOutlet weak var goForwardBtn: UIBarButtonItem!
 @IBOutlet weak var itemWebView: UIWebView!

 override func viewDidLoad() {
    super.viewDidLoad()

    let url = NSURL (string: "www.google.com")
    let requestObj = NSURLRequest(URL: url)
    itemWebView.loadRequest(requestObj)

    itemWebView.delegate = self


    goBackBtn.enabled = false
    goForwardBtn.enabled = false
}


func webViewDidFinishLoad(webView: UIWebView) {
    goBackBtn.enabled = itemWebView.canGoBack
    goForwardBtn.enabled = itemWebView.canGoForward  
}

@IBAction func forward(sender: AnyObject) {

    itemWebView.goForward()

}


@IBAction func back(sender: AnyObject) {
     itemWebView.goBack()
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!