如何设置我的UISearchBar连接到我的UIWebView能够与一个字,而不是一个网址在谷歌搜索。 例如搜索苹果,而不是http://www.apple.com
继承人到目前为止我的代码
import UIKit
import WebKit
class ViewController: UIViewController, UISearchBarDelegate {
@IBOutlet weak var searchBar: UISearchBar!
@IBOutlet weak var webView: UIWebView!
func searchBarSearchButtonClicked(searchBar: UISearchBar!) {
searchBar.resignFirstResponder()
var text = searchBar.text
var url = NSURL(string: text) //type "http://www.apple.com"
var req = NSURLRequest(URL:url)
self.webView!.loadRequest(req)
}
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL(string: "http://google.com")
let request = NSURLRequest(URL: url)
webView.loadRequest(request)
self.searchBar.delegate = self
}
}