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

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

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

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

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

Q&A

解決済

1回答

1212閲覧

Todoアプリでタスクを追加した瞬間にエラー発生

nekokichi

総合スコア54

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

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

0グッド

0クリップ

投稿2018/09/04 05:37

Todoアプリを作って、シミュレータを起動したらエラーが出て困っています。

エラーは、

AppDelegate

1class AppDelegate: UIResponder, UIApplicationDelegate { //Thread 1: signal SIGABRT

で発生しました。

どうか、お解決方法を教えてください。

import UIKit class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource { @IBOutlet weak var tableView: UITableView! //セルの配列 var result_array = [String]() override func viewDidLoad() { super.viewDidLoad() //デリゲートを取得 tableView.delegate = self tableView.dataSource = self } override func viewWillAppear(_ animated: Bool) { //配列に保存したセルを格納する if UserDefaults.standard.object(forKey: "array") != nil { result_array = UserDefaults.standard.object(forKey: "array") as! [String] } //セル数、セクション数、セルを呼び出す、を実行する tableView.reloadData() } func numberOfSections(in tableView: UITableView) -> Int { return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return result_array.count } //セルが生成されたら実行 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { //セルに追加したタスクを格納 let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) //タスクをセルのテキスト欄に追加 cell.textLabel?.text = result_array[indexPath.row] return cell } func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { //スワイプしたセルを消去 result_array.remove(at: indexPath.row) //セルを保存 UserDefaults.standard.set(result_array, forKey: "array") //テーブルビューを更新 tableView.reloadData() } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }

TodoViewController

1i![イメージ説明](5c0de63fe388c1e753403d5ad2bd7eea.png)UIKit 2 3class TodoViewController: UIViewController { 4 5 //配列 6 var array = [String]() 7 8 @IBOutlet weak var textField: UITextField! 9 10 @IBAction func addTodo(_ sender: Any) { 11 12 //一旦、現在の配列状況を保存する 13 if UserDefaults.standard.object(forKey: "array") != nil { 14 array = UserDefaults.standard.object(forKey: "array") as! [String] 15 } 16 17 //入力値を配列に追加 18 array.append(textField.text!) 19 20 //タスクを追加 21 UserDefaults.standard.set(array, forKey: "array") 22 23 //前画面に戻る 24 self.navigationController?.popViewController(animated: true) 25 26 } 27 28 29 override func viewDidLoad() { 30 super.viewDidLoad() 31 32 33 34 // Do any additional setup after loading the view. 35 } 36 37 override func didReceiveMemoryWarning() { 38 super.didReceiveMemoryWarning() 39 // Dispose of any resources that can be recreated. 40 } 41 42 43 /* 44 // MARK: - Navigation 45 46 // In a storyboard-based application, you will often want to do a little preparation before navigation 47 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 48 // Get the new view controller using segue.destinationViewController. 49 // Pass the selected object to the new view controller. 50 } 51 */ 52 53} 54

イメージ説明

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

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

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

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

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

guest

回答1

0

自己解決

実はsegueをpushにしていたら、iOS8.0以降では使えない、と示すエラーがありました。
segueをshowにしたら解決しました。

投稿2018/09/04 09:03

nekokichi

総合スコア54

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問