简体   繁体   English

在搜索时摆脱单词之间的+

[英]get rid of + between words while searching

I'm doing an iOS application where the user insert a movie title and the application tells the user the plot and actor and display an image for the movie. 我正在做一个iOS应用程序,用户插入电影标题,应用程序告诉用户剧情和演员,并显示电影的图像。
The database is http://www.omdbapi.com/ 数据库是http://www.omdbapi.com/
The application works fine but with movies with 2 words i must insert a + to make it work (is there a way to fix that..) 该应用程序工作正常,但有2个单词的电影,我必须插入一个+ ,使其工作(是否有办法解决..)

OMDB is a class with parameters actors and plot and image OMDB是一个具有参数actor,plot和image的类

public func searchBarSearchButtonClicked(_ searchBar: UISearchBar){
    let searchtext=searchBar.text
           getData(withTitle: searchtext!)
            {

                (result: String?, data: Omdb?, error: String?) in
                if result == "Success"
                {
                    self.tempOmdb = data!
                    self.tableview.reloadData()

                                         }
                else{
                    print(error)
                }
            }

}

All you need to do is replace the spaces with plusses. 您需要做的就是用加号替换空格。

let modifiedSearchText = searchtext.replacingOccurrences(of: " ", with: "+")

So here is your updated code (I also cleaned it up a little): 所以这是你更新的代码(我也清理了一下):

public func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
    guard let searchtext = searchBar.text else { return }
    let modifiedSearchText = searchtext.replacingOccurrences(of: " ", with: "+")
    getData(withTitle: modifiedSearchText) { (result: String?, data: Omdb?, error: String?) in
        if result == "Success" {
            self.tempOmdb = data!
            self.tableview.reloadData()
        }
        else {
            print(error)
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM