gpt4 book ai didi

ios - 如何在 searchBar 中设置 http 不区分大小写?

转载 作者:行者123 更新时间:2023-11-30 13:24:26 25 4
gpt4 key购买 nike

webView 顶部有一个 searchBar,以便用户可以输入新的互联网地址。我发现当 http 更改为 Http 时它不再起作用。如何设置网址不区分大小写?谢谢!

func searchBarSearchButtonClicked(searchBar: UISearchBar) {

searchBar.resignFirstResponder()

if searchBar.text != nil {

let address = searchBar.text!

if address.containsString("http://") || address.containsString("https://") {

let str = address

if let newUrl = NSURL(string: str) {

let newRequest = NSURLRequest(URL: newUrl)

myWebView.loadRequest(newRequest)

}

} else {

let str = "http://" + String(address)

if let newUrl = NSURL(string: str) {

let newRequest = NSURLRequest(URL: newUrl)

myWebView.loadRequest(newRequest)

}

}

}

}

最佳答案

引用此:

Here is a link to another stack overflow talking about uppercase and lowercase strings.

您应该能够通过执行以下操作将整个字符串变为小写:

let address = searBar.text!.lowercaseString

这应该将地址字符串转换为全部小写。您可能还需要考虑更改要禁用的搜索栏框的大小写。

另一个解决方案可能是检查address.contains("Http://")

最好,乔

关于ios - 如何在 searchBar 中设置 http 不区分大小写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37395131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com