Fatal error: Unexpectedly found nil while unwrapping an Optional value
現在swift4を用いて簡単なRSSReaderを作っています。
その際に、不慣れな自分では解決できない問題に当たってしまいました。
tableviewCellを呼び出し、そのLabelViewに代入しようとすると以下のエラーが出てしまいます。
###発生している問題・エラーメッセージ
Fatal error: Unexpectedly found nil while unwrapping an Optional value
###該当のソースコード
テーブル側のコード import UIKit import Alamofire import SwiftyJSON class TableViewController: UITableViewController { var fetchFrom: String? var articlesList: [[String: String]] = [] override func viewDidLoad() { super.viewDidLoad() tableView.delegate = self tableView.dataSource = self self.tableView.register(ArticleTableViewCell.self, forCellReuseIdentifier: "ArticleTableViewCellXib") // // tableView.register(UINib(nibName: "ArticleTableViewCell", bundle: nil), forCellReuseIdentifier: "ArticleTableViewCellXib") Alamofire.request(fetchFrom!, parameters: nil).responseJSON{ response in let json = JSON(response.result.value) json["articles"].forEach{(_, article) in let articleInfo: Dictionary<String, String> = ["title": article["title"].string!, "description": article["description"].string!, "url": article["url"].string!, "imageUrl": article["urlToImage"].string!] self.articlesList.append(articleInfo) } self.tableView.reloadData() } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } // MARK: - Table view data source override func numberOfSections(in tableView: UITableView) -> Int { // #warning Incomplete implementation, return the number of sections return 1 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // #warning Incomplete implementation, return the number of rows return self.articlesList.count } override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 90 } //## 問題の箇所 ## override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "ArticleTableViewCellXib", for: indexPath) as! ArticleTableViewCell cell.articleDescription.text = self.articlesList[indexPath.row]["description"] <== ここの代入の箇所でエラーが発生します cell.articleTitle.text = self.articlesList[indexPath.row]["title"] <== ここの代入の箇所でエラーが発生します return cell } }
せる側のコード class ArticleTableViewCell: UITableViewCell { var title: String? var explain: String? @IBOutlet weak var articleTitle: UILabel! @IBOutlet weak var articleDescription: UILabel! override func awakeFromNib() { super.awakeFromNib() print("hello wrold") // Initialization code } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) // Configure the view for the selected state } }
###試したこと
if文を用いてnilかどうかのチェックなど行ったり、
代入予定の値をprintしてみてもnilであったことはなかったです
###補足情報(言語/FW/ツール等のバージョンなど)
皆さんのお知恵をお借りできれば幸いです
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/12 11:49
2017/11/14 01:38