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

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

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

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

Swift

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

Q&A

解決済

1回答

506閲覧

UserDefaultsとTableViewを使ってToDoアプリ作ったのですが、Thread 1:signal SIGABRTとエラーが出る

hik_

総合スコア42

Xcode

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

Swift

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

0グッド

0クリップ

投稿2018/08/25 05:08

編集2018/08/25 06:21

前提・実現したいこと

勉強のためToDoアプリを作っていたのですが、コードを書き、シミュレーターを起動するとシュミュレーターが落ち
Thread 1:signal SIGABRTとエラーが出てしまいます。

発生している問題・エラーメッセージ

Thread 1:signal SIGABRT

### 該当のソースコード import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { // Thread 1:signal SIGABRT var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. } func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. } func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } }

エラーが出ていない部分のソースコード

import UIKit var nakami = [String]() class TwoViewController: UIViewController { @IBOutlet var ToDoTextField: UITextField! @IBAction func ToDoAddButton(_ sender: Any) { // ToDoTextFieldに入力した文字をnakamiに入れる nakami.append(ToDoTextField.text!) // 保存する UserDefaults.standard.set(nakami, forKey: "ToDoList") } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ }
import UIKit class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return nakami.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) cell.textLabel!.text = nakami[indexPath.row] return cell } override func viewDidLoad() { super.viewDidLoad() if UserDefaults.standard.object(forKey: "ToDoList") != nil { nakami = UserDefaults.standard.object(forKey: "ToDoList") as! [String] } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }

試したこと

検索して解決方法を色々調べたのですが、解決できませんでした。
初心者なので質問も至らない点があるかと思います。すみません。もし不足している情報があれば迅速に追加します。

補足情報(FW/ツールのバージョンなど)

Swift4です。

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

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

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

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

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

xAxis

2018/08/25 05:51

コードが```で囲えてないですね。そこを修正してください。それとエラー吐いてるのがどこなのかも教えてください。コメントアウトしてとかで。
hik_

2018/08/25 06:23

ご回答ありがとうございます。修正しました。不備や情報不足がありましたら迅速に追加します。よろしくお願いします。
guest

回答1

0

ベストアンサー

エラーログ確認しました。
これはUITableViewCellのidentifierが原因ですね。

上記コード内にある

swift

1let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)

のwithIdentifierに"cell"とありますが、このidentifierとStoryboard上のCellのIdentifierが同一か確認してください。Storyboard上のCellのIdentifierの確認方法はAttributes Inspector内にIdentifierを入力する欄がありますからそこで。Attributes InspectorはStoryboardを開いた時右側に出てくる欄の上部のボタンバー内の、左から4番目、または右から3番目です。下矢印っぽいやつですね。

投稿2018/08/25 06:32

編集2018/08/25 07:10
xAxis

総合スコア1349

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

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

hik_

2018/08/25 06:55 編集

ご返信ありがとうございます。 textFieldとUIButtonの再接続をしましたがエラーが起きました。 ログは 2018-08-25 15:52:55.602270+0900 ToDo(Study)(1)[2462:307744] *** Assertion failure in -[UITableView _dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3698.54.4/UITableView.m:7879 2018-08-25 15:52:55.605335+0900 ToDo(Study)(1)[2462:307744] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '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' です
hik_

2018/08/25 07:24

ご返信ありがとうございます。今withIdentifierがcellで StoryboardのIdentifierがCellだったので、withIdentifierのcellをCellにかえたら無事ビルドできました!! 本当にありがとうございます。
xAxis

2018/08/25 07:29

無事解決して何よりです。この手のエラーはよくある人為的なミスですね。恥ずかしながら自分も良くやります。 今回の解決の糸口になったのはエラーのreason以下の部分です。ここを読む、または検索してみると解決につながることが多いので覚えておくと良いですよ。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問