Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I create back, forward, and refresh buttons for a UIWebView programmatically?

I currently have a webview created but I do not want to use interface builder to create the back, forward, and refresh buttons. How would I create these buttons programmatically? I know how to create regular buttons with code, but as for webView delegate buttons, I am lost and have not been able to find many resources on it.

like image 752
Linux world Avatar asked Feb 26 '23 07:02

Linux world


1 Answers

From the UIWebView documentation:

If you allow the user to move back and forward through the webpage history, then you can use the goBack and goForward methods as actions for buttons. Use the canGoBack and canGoForward properties to disable the buttons when the user can’t move in a direction.

Setting up the buttons would then use addTarget:action:forControlEvents: (as pointed out by Sven):

[myBackButton addTarget:myWebView
                 action:@selector(goBack)
       forControlEvents:UIControlEventTouchDown];

If you want to get fancy and enable/disable the buttons based on the canGoBack and canGoForward properties, you will have to add some KVO notifications to your UIController.

like image 98
e.James Avatar answered Apr 30 '23 12:04

e.James