前提・実現したいこと
Alamofire,SwiftyJSONを利用しapiを叩き、Qiitaの記事一覧をtableViewに表示、WebViewに記事を表示するアプリを作成したい。
発生している問題・エラーメッセージ
Main Storyboardへの接続がおかしい
Thread 1: signal SIGABRT
該当のソースコード
swift
1class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { 2 3 var articles: [[String:String?]] = [] 4 5 6 let cellId = "cellId" 7 let tableView: UITableView = { 8 let t = UITableView() 9 return t 10 }() 11 12 override func viewDidLoad() { 13 super.viewDidLoad() 14 15 view.addSubview(tableView) 16 tableView.frame.size = view.frame.size 17 tableView.delegate = self 18 tableView.dataSource = self 19 tableView.register(UITableViewCell.self, forCellReuseIdentifier: cellId) 20 navigationItem.title = "Qiita Client" 21 getQiitaApi() 22 } 23 24 func getQiitaApi(){ 25 AF.request("https://qiita.com/api/v2/items?page=1&per_page=20", method: .get).validate().responseJSON { response in 26 27 switch response.result { 28 case .success(let value): 29 let json = JSON(value) 30 json.forEach {(_, json) in 31 let article: [String: String?] = [ 32 "title": json["title"].string, 33 "userId": json["user"]["id"].string, 34 "url": json["url"].string 35 ] 36 self.articles.append(article) 37 } 38 self.tableView.reloadData() 39 40 case .failure(let error): 41 print(error) 42 } 43 } 44 } 45 46 47 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 48 return articles.count 49 50 } 51 52 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 53 let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) 54 cell.backgroundColor = .white 55 let article = articles[indexPath.row] 56 57 let ViewController2 = self.storyboard?.instantiateViewController(withIdentifier: "ViewController2") as! ViewController2 58 self.present(ViewController2, animated: true, completion: nil) 59 60 cell.textLabel?.text = article["title"]! 61 cell.detailTextLabel?.text = article["userId"]! 62 63 return cell 64 } 65 66 67 68} 69
試したこと
tableViewを@IBOutlet weak var Tableview: UITableView!と定義してTableViewとViewControllerを接続してみたが、今度はsubViewに関するエラーが出てしまった。(よくわかっていません)
補足情報
具体的なエラーはどの行ででていますでしょうか。
また、Xcode の一番上を見ると、警告が3つ(⚠️3)となっていますが、これらの内容はどんな感じでしょうか。
let ViewController2 = self.storyboard?.instantiateViewController(withIdentifier: "ViewController2") as! ViewController2 エラーはこの行に対して行われています。
また、エラーはViewControllerの識別子に関するエラーと、よく理解していないので分かりませんが以下のようなエラーです。
Capabilities for Signing & Capabilities may not function correctly because its entitlements use a placeholder team ID. To resolve this, select a development team in the qiitaApp editor.
後半のエラーですが、一回 Xcode のプロジェクト(ここのプロジェクトではなくて、開発者設定など)を行えばこのエラーが出ることはほとんどないので、私自身このエラーについてよく知っているわけではありませんが、エラーメッセージで検索すると例えば次のような事例がありますので、確認していただけますでしょうか。
https://pikucha.sakura.ne.jp/blog/2019/11/25/2019%E5%B9%B4%E4%BB%8A%E6%97%A5%E3%81%AE%E3%83%93%E3%83%AB%E3%83%89%E3%82%A8%E3%83%A9%E3%83%BC%E3%80%81%E3%83%AF%E3%83%BC%E3%83%8B%E3%83%B3%E3%82%B0capabilities-for-signing-capabilities-may-not-func/
後半のエラーについては解消しました。ありがとうございます。また、識別子の警告に関しても解消しました。
回答1件
あなたの回答
tips
プレビュー