你需要设置
SEARCH_RESULTS_ADDRESS
它被使用了。
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
albumSearch = searchBar.text
albumInfo = []
//###
SEARCH_RESULTS_ADDRESS = "\(BASE_URL)\(choiceSearch!).search&\(choiceSearch!)=\(albumSearch!)&api_key=\(API_KEY)&format=json"
print(SEARCH_RESULTS_ADDRESS)
getData(completion: { (complete) in
DispatchQueue.main.async {
self.tableView.reloadData()
print("Tony Finishedediting \(albumSearch!)")
}
})
}
(补充)
假设您可以修改
AddressDataService
:
func getAlbumData(_ urlString: String, completion: @escaping (_ finished: Bool) -> ()) {
print(urlString)
guard let url = URL(string: urlString) else {
print("ursString is invalid")
return
}
//...
}
你可以把它当作:
func getData(_ urlString: String, completion: @escaping (_ finished: Bool) -> ()) {
AlbumDataService().getAlbumData(urlString) { complete in
completion(true)
}
}
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
albumSearch = searchBar.text
albumInfo = []
let searchResultsAddress = "\(BASE_URL)\(choiceSearch!).search&\(choiceSearch!)=\(albumSearch!)&api_key=\(API_KEY)&format=json"
getData(searchResultsAddress) { complete in
DispatchQueue.main.async {
self.tableView.reloadData()
print("Tony Finishedediting \(albumSearch!)")
}
}
}