如何以编程方式创建import urllib
import json
serviceurl = 'http://python-data.dr-chuck.net/geojson'
while True:
address = raw_input('Enter location: ')
if len(address) < 1 : break
url = serviceurl + '?' + urllib.urlencode({'sensor':'false', 'address': address})
print 'Retrieving', url
uh = urllib.urlopen(url)
data = uh.read()
print 'Retrieved',len(data),'characters'
try:
js = json.loads(str(data))
except:
js = None
if 'status' not in js or js['status'] != 'OK':
print '==== Failure To Retrieve ===='
print data
continue
print json.dumps(js, indent=4)
placeid = js['results'][0]['place_id']
print "Place ID: ", placeid
print placeid
print location
重新加载+ UIwebview
按钮。
如何调用以下功能
goback/forward
更新了当前代码:
func reload()
func goBack()
func goForward()
答案 0 :(得分:4)
根据WebView的Apple文档 (https://developer.apple.com/library/mac/documentation/Cocoa/Reference/WebKit/Classes/WebView_Class/)
您可以像这样连接相应的按钮插座:
@IBAction func goBack(sender: AnyObject) {
self.webView.goBack()
}
@IBAction func reload(sender: AnyObject) {
self.webView.reload()
}
@IBAction func forward(sender: AnyObject) {
self.webView.goForward()
}
还要检查canGoBack和canGoForward是否设置为true(只读)。
如果按钮也是以编程方式创建的,您可以添加选择器,例如Selector(&#34; goBack&#34;)并创建一个func goBack(){}
对于ObjectiveC,您可以这样做:
- (IBAction)browserGoBack
{
[self.webView goBack];
}
- (IBAction)browserGoForward
{
[self.webView goForward];
}
- (IBAction)browserRefresh
{
[self.webView reload];
}
答案 1 :(得分:2)
这是答案
@IBAction func reload(sender: UIBarButtonItem) {
webview.reload()
}
@IBAction func back(sender: UIBarButtonItem) {
webview.goBack()
}
@IBAction func forward(sender: UIBarButtonItem) {
webview.goForward()
}
答案 2 :(得分:2)
您可以对按钮操作进行额外检查:
@IBAction func barBackButtonAction(sender: AnyObject) {
if webView.canGoBack {
webView.goBack()
}
}
@IBAction func barForwardButtonAction(sender: AnyObject) {
if webView.canGoForward{
webView.goForward()
}
}
答案 3 :(得分:0)
使用后退,前进,重新加载,停止按钮创建UI Web视图
class ViewController: UIViewController {
@IBOutlet weak var webview1: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://www.google.co.in")
let requestobj = URLRequest(url:url!)
webview1.loadRequest(requestobj)
}
@IBAction func back_btn(_ sender: Any) {
self.webview1.goBack()
}
@IBAction func forward_btn(_ sender: Any) {
self.webview1.goForward()
}
@IBAction func reload_btn(_ sender: Any) {
self.webview1.reload()
}
@IBAction func stop_btn(_ sender: Any) {
self.webview1.stopLoading()
}
}