当我运行你的应用程序而不是崩溃时,它也显示错误终止应用程序由于未捕获的异常' NSInvalidArgumentException',reasonNSCFDictionary长度]:无法识别的选择器发送到实例0x60000006df80'。这个应用程序是否是我试着通过使用这个应用程序找到更好的条件,而构建没有错误,但是当我运行这个应用程序时,它显示错误无法识别的选择器发送到实例0x60000006df80'。问题是在func searchBarSearchButtonClicked(_ searchBar: UISearchBar)在这一行。所以,请帮助我,以便我接下一部分。
@IBOutlet weak var searchBar: UISearchBar!
@IBOutlet weak var cityLbl: UILabel!
@IBOutlet weak var conditionLbl: UILabel!
@IBOutlet weak var degreeLbl: UILabel!
@IBOutlet weak var imgView: UIImageView!
var degree: Int!
var condition:String!
var imgURL:String!
var city:String!
var exists: Bool = true
override func viewDidLoad() {
super.viewDidLoad()
searchBar.delegate = self
}
func searchBarSearchButtonClicked (_ searchBar: UISearchBar)
{
let urlRequest = URLRequest(url: URL(string: "https://api.apixu.com/v1/current.json?key=04e2f1e6e7db4897aee91005171207&q=\(searchBar.text!.replacingOccurrences(of:" ", with: "%20"))")!)
let task = URLSession.shared.dataTask(with: urlRequest) { (data, responce, error) in
if error == nil{
do{
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! [String: AnyObject]
if let current = json["current"] as? [String:AnyObject]{
if let temp = current["temp_c"] as? Int{
self.degree = temp
}
if let condition = current["condition"] as? [String:AnyObject]{
self.condition = condition["text"] as! String
let icon = condition["icon"] as! String
self.imgURL = "http:\(icon)"
}
}
if let location = json["location"] as? [String:AnyObject]{
self.city = location["name"] as! String
}
if let _ = json["error"] {
self.exists = false
}
DispatchQueue.main.async {
if self.exists{
self.degreeLbl.isHidden = false
self.cityLbl.isHidden = false
self.conditionLbl.isHidden = false
self.degreeLbl.text = "\(self.degree.description)°"
self.cityLbl.text = self.city
self.conditionLbl.text = self.condition
}else{
self.degreeLbl.isHidden = true
self.cityLbl.isHidden = true
self.conditionLbl.isHidden = true
self.cityLbl.text = "City does not Match"
self.exists = true
self.imgView.downloadImage(from: self.imgURL)
}
}
} catch let jsonError
{
print(jsonError.localizedDescription)
}
}
}
task.resume()
}
}
答案 0 :(得分:0)
在info.plist中,主故事板文件基本名称应为Main不为空