2017-07-13 159 views
0

當我運行你的應用程序比它崩潰還顯示錯誤終止應用程序由於未捕獲的異常'NSInvalidArgumentException',reasonNSCFDictionary長度]:無法識別的選擇器發送到實例0x60000006df80'.This應用程序是否條件。我試圖通過使用這個應用程序找到更好的條件,而建設沒有錯誤,但是當我運行這個應用程序,它顯示錯誤無法識別的選擇器發送到實例0x60000006df80'.So問題是在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

在info.plist中的主要故事板文件基本名稱的名稱應該是主要不是空

相關問題