質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

623閲覧

ToDoアプリを作っているのですが、エラーが出てしまいます。

taiseiswift

総合スコア20

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2020/06/19 15:08

編集2020/06/19 16:30

ToDoアプリを作っていて追加ボタンを押すとアラートが出てテキストを入力しOKボタンを押すとセルに表示させたいのですが、テキストを打ち込み追加を押すとこのようなエラーが出てしまいます。
Thread 1: Exception: "unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard"

なぜこのようなエラーがでてしまうのでしょうか?```swift

import

1 2class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { 3 4 @IBOutlet weak var tableView: UITableView! 5 // taskの配列 6 var tasks = [String]() 7 8 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 9 return tasks.count 10 } 11 12 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 13 let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) 14 cell.textLabel?.text = tasks[indexPath.row] 15 print(tasks[indexPath.row]) 16 return cell 17 } 18 19 override func viewDidLoad() { 20 super.viewDidLoad() 21 tableView.delegate = self 22 tableView.dataSource = self 23 // Do any additional setup after loading the view. 24 } 25 26 @IBAction func addAction(_ sender: UIBarButtonItem) { 27 let alertController = UIAlertController(title: title, message: "", preferredStyle: .alert) 28 let okAlert = UIAlertAction(title: "OK", style: .default) { (action) in 29 let textFiels = alertController.textFields![0] 30 let tasktitle = textFiels.text 31 self.tasks.append(tasktitle!) 32 self.tableView.reloadData() 33 } 34 let cancelAlert = UIAlertAction(title: "キャンセル", style: .cancel, handler: nil) 35 alertController.addTextField { (textField: UITextField) -> Void in 36 textField.placeholder = "テキスト" 37 } 38 alertController.addAction(okAlert) 39 alertController.addAction(cancelAlert) 40 present(alertController, animated: true, completion: nil) 41 } 42 43} 44```![イメージ説明](6adc797f5530a2c629f0dcdd3c39ccc3.png)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Storyboard で Table View に Table View Cell を追加して、その Identifier に Cell と設定しましょう。
イメージ説明


Table View Cell は Table View の中に作りましょう。Cell をドラッグして移動できるはず。
イメージ説明

投稿2020/06/19 15:26

編集2020/06/19 16:38
hoshi-takanori

総合スコア7895

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

taiseiswift

2020/06/19 15:33

情報不足で申し訳ありません。 すでにやっていて何度も確認したのですがだめでした。
hoshi-takanori

2020/06/19 16:15

うーん、質問文のソースを Xcode に貼ったらこれで動きましたけど…。 どうしてもダメなら質問文を編集して Storyboard のスクショを貼ってもらえますか? あと、編集のついでに Swift のコードは <code> 機能を使ってもらえると嬉しいです。 https://orenodiy.com/teratail-question-howto#toc8
taiseiswift

2020/06/19 16:31

不慣れなものですいません。 更新いたしました。
taiseiswift

2020/06/19 16:44

そういうことだったのですね。 勉強になりました。本当にありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問