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

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

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

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

Swift

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

Q&A

解決済

1回答

228閲覧

Thread 1: signal SIGABRTでページが画面遷移しない

pompompurin

総合スコア12

Xcode

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

Swift

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

0グッド

0クリップ

投稿2018/09/12 05:49

編集2018/09/12 06:11

Xcode9.4.1
Swift4

ストーリーボードでは正しくコネクトしています。

buttomをクリックすると次のページに遷移する予定だったのですが、クリックするとThread 1: signal SIGABRTエラーになります。

コンソールには、
libc++abi.dylib: terminating with uncaught exception of type NSException
と表示されています。
流れとしては、ViewController.swift→NewViewControllerに画面遷移です。
昨日までは画面遷移できていたのに、今日次のページの作業をしている途中に遷移しなくなりました。
すみませんがエラーの原因を教えていただきたいです。
どこが原因でエラーが出ているのかわからない状態なので、関係ありそうな所を全て載せています。
エラーが出たのはAppDelegate.swiftの中で、画面遷移しようとした元のページはViewController.swiftです。
よろしくお願いいたします。

エラーが出ていた場所
AppDelegate.swift

import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {  **←ここに出ていました。** var window: UIWindow?

ViewController.swift

import UIKit class ViewController: UIViewController { @IBOutlet weak var cTabBar: UITabBar! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } //スイカの子役カウンター @IBOutlet weak var sgoukei: UILabel! @IBAction func spuramai(_ sender: UIStepper) { let num = Int(sender.value) sgoukei.text = String(num) } //チェリーの子役カウンター @IBOutlet var tgoukei: UILabel! @IBAction func tpuramai(_ sender: UIStepper) { let num1 = Int(sender.value) tgoukei.text = String(num1) } //ベルの子役カウンター @IBOutlet var bgoukei: UILabel! @IBAction func bpuramai(_ sender: UIStepper) { let num2 = Int(sender.value) bgoukei.text = String(num2) } //チャンス目Aの子役カウンター @IBOutlet var tAgoukei: UILabel! @IBAction func tApuramai(_ sender: UIStepper) { let num3 = Int(sender.value) tAgoukei.text = String(num3) } //チャンス目Bの子役カウンター @IBOutlet var tBgoukei: UILabel! @IBAction func tBpuramai(_ sender: UIStepper) { let num4 = Int(sender.value) tBgoukei.text = String(num4) } }

NewViewController.swift

import UIKit class NewViewController: UIViewController { 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. } @IBOutlet weak var tenpomei: UILabel! /* // 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. } */ }

コンソールの画面です

2018-09-12 14:38:36.859928+0900 newfile[24282:3136946] -[newfile.NewViewController numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x7fee82c134f0 2018-09-12 14:38:36.864838+0900 newfile[24282:3136946] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[newfile.NewViewController numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x7fee82c134f0' *** First throw call stack: ( 0 CoreFoundation 0x0000000104ec81e6 __exceptionPreprocess + 294 1 libobjc.A.dylib 0x000000010132e031 objc_exception_throw + 48 2 CoreFoundation 0x0000000104f49784 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 UIKit 0x0000000101df86db -[UIResponder doesNotRecognizeSelector:] + 295 4 CoreFoundation 0x0000000104e4a898 ___forwarding___ + 1432 5 CoreFoundation 0x0000000104e4a278 _CF_forwarding_prep_0 + 120 6 UIKit 0x0000000101baa823 -[UIPickerView _delegateNumberOfComponents] + 55 7 UIKit 0x0000000101ba9947 -[UIPickerView _updateSelectedRows] + 91 8 UIKit 0x0000000101ba9a15 -[UIPickerView didMoveToWindow] + 101 9 UIKit 0x0000000101c8fef5 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1718 10 UIKit 0x0000000101c8fb38 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 761 11 UIKit 0x0000000101c820b4 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 151 12 UIKit 0x0000000101c81f8a -[UIView(Hierarchy) _postMovedFromSuperview:] + 808 13 UIKit 0x0000000101c929cb -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1940 14 UIKit 0x0000000101d391a6 -[UITransitionView transition:fromView:toView:removeFromView:] + 1371 15 UIKit 0x000000010297405a -[UIViewControllerBuiltinTransitionViewAnimator animateTransition:] + 2056 16 UIKit 0x0000000101d3f68e __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 3033 17 UIKit 0x0000000101bd54b3 _runAfterCACommitDeferredBlocks + 318 18 UIKit 0x0000000101bc471e _cleanUpAfterCAFlushAndRunDeferredBlocks + 388 19 UIKit 0x0000000101bf2ea5 _afterCACommitHandler + 137 20 CoreFoundation 0x0000000104e6a607 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 21 CoreFoundation 0x0000000104e6a55e __CFRunLoopDoObservers + 430 22 CoreFoundation 0x0000000104e4eb81 __CFRunLoopRun + 1537 23 CoreFoundation 0x0000000104e4e30b CFRunLoopRunSpecific + 635 24 GraphicsServices 0x00000001077c0a73 GSEventRunModal + 62 25 UIKit 0x0000000101bca057 UIApplicationMain + 159 26 newfile 0x0000000100a20567 main + 55 27 libdyld.dylib 0x00000001060a9955 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

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

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

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

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

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

fuzzball

2018/09/12 05:53

NewViewControllerのコードを書いて下さい。
coco_bauer

2018/09/12 05:57

画面遷移できていた昨日時点のコードと、画面遷移できなくなっている現在のコードの両方を質問に追加できませんか? 2つのコードの差異部分がトラブルの起源だと思われますので。
pompompurin

2018/09/12 06:13

fuzzballさん、 NewViewControllerのコードを追加しました。
pompompurin

2018/09/12 06:14

coco_bauerさん、 すみません。昨日のコードを探しても上書き保存してしまいなくなってしまいました。
guest

回答1

0

ベストアンサー

遷移先のViewControllerでUIPickerViewを使っているようですが、UIPickerViewDataSourceの必須メソッドnumberOfComponents(in:)が無いせいで落ちていると思われます。

UIPickerViewDataSourceの、

swift

1numberOfComponents(in:) 2pickerView(_:numberOfRowsInComponent:)

は必須メソッドですので、ダミーでもなんでもいいので、とりあえず実装して下さい。

ダミーの例

swift

1func numberOfComponents(in pickerView: UIPickerView) -> Int { 2 return 1 3} 4 5func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 6 return 1 7}

投稿2018/09/12 05:58

編集2018/09/12 06:00
fuzzball

総合スコア16731

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

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

pompompurin

2018/09/12 06:12

教えていただきありがとうございます。ダミーを入れて実装しましたが同じエラーが出てしまいました。
fuzzball

2018/09/12 06:23 編集

ダミーを入れたコードを書いて下さい。(どこに書いたのか確認したいので)
pompompurin

2018/09/12 10:09

解決しました。 class NewViewController: UIViewController { のところに UIPickerViewDelegate, UIPickerViewDataSource を入れるのを忘れていました。初歩的なミスにもお付き合いいただき、すごく助かりました! ありがとうございました!ベストアンサーにさせていただきます!
fuzzball

2018/09/12 10:34 編集

念のために書いておきますが、落ちるかどうかにその記述は直接関係ありません。 その記述をすることで、必要なメソッドが無いときにエラーが発生するようになります。
pompompurin

2018/09/12 14:42

直接関係ないということは、他に問題があるということでしょうか? UIPickerViewDelegate, UIPickerViewDataSourceを追加しただけで画面遷移はできるようになったのですが(;_;)
fuzzball

2018/09/13 00:37

すみません、私の勘違いでした。昨日書き込む前にテストしたときも落ちなかった(つもりだった)のですが、完全に思い込みのなせる技ですね。「念のため」が蛇足になってしまいました‥。 ということで、「UIPickerViewDelegate、UIPickerViewDataSourceの記述」と「必須メソッドの実装」が正しい解決方法となります。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問