请求网站时,UIsearchbar没有响应

时间:2018-09-11 20:14:55

标签: ios iphone xcode uisearchbar

我正在尝试向搜索栏发送地址,但是什么也没发生:

override func viewDidLoad() {  

if let url = URL(string: "https://www.google.com"){ 

        let requestObj = URLRequest(url: url) 

        Webview.loadRequest(requestObj)
    }
    SearchBar.text = "http://" 
}

func searchBarSearchButtonClicked(searchbar: UISearchBar) {

    searchbar.resignFirstResponder()

    let text = SearchBar.text

let url = NSURL(string: text!)

    let urlRequest:URLRequest = URLRequest(url: url! as URL)

    let request = NSURLRequest(URL: url! as URL)

    Webview.loadRequest(urlRequest)   
    }
}

1 个答案:

答案 0 :(得分:0)

您的searchBar委托获得了错误的函数签名。

 func searchBarSearchButtonClicked(_ searchBar: UISearchBar){
// func searchBarSearchButtonClicked(searchbar: UISearchBar) {

因此您的搜索无效