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

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

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

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

Q&A

解決済

1回答

1123閲覧

SWIFTでtextfieldへ入力した数値によって画面遷移したい

amam.jamjam

総合スコア6

Swift

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

0グッド

0クリップ

投稿2019/12/13 09:14

プログラミング初心者です。

SWIFTでtextfieldに入力した数値がただしければ(100ならば)OKページへ、正しくなければ(100以外ならば)NGページへ画面遷移するアプリを作成しています。
コードに対してエラーは出ていないのですシミュレーターを起動させようとすると落ちてしまい、[Thread 1: signal SIGABRT]という表示がされています。

ソースコードは以下のようになっています。

SWIFT

1import UIKit 2 3class KoziroViewController: UIViewController, UITextFieldDelegate { 4 5 @IBOutlet weak var textNyuryoku: UITextField! 6 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 10 // Do any additional setup after loading the view. 11 } 12 13 override func didReceiveMemoryWarning() { 14 super.didReceiveMemoryWarning() 15 // Dispose of any resources that can be recreated. 16 } 17 18 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 19 self.view.endEditing(true) 20 } 21 22 @IBAction func GotoPage(_ sender: Any) { 23 let Atai = Int(textNyuryoku.text!)! 24 if Atai == 100{ 25 self.performSegue(withIdentifier: "toOK", sender: nil) 26 }else{ 27 self.performSegue(withIdentifier: "toNG", sender: nil) 28 } 29 } 30 } 31

また、デバックの欄には以下のように表示されています。

2019-12-13 17:51:30.182316+0900 matsumoto[5724:155182] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<matsumoto.KoziroViewController 0x7fa669c11020> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key DrugKoziro.' *** First throw call stack: ( 0 CoreFoundation 0x000000010a26e1e6 __exceptionPreprocess + 294 1 libobjc.A.dylib 0x0000000106591031 objc_exception_throw + 48 2 CoreFoundation 0x000000010a26e0b9 -[NSException raise] + 9 3 Foundation 0x00000001059ceb47 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292 4 UIKit 0x000000010750dec0 -[UIViewController setValue:forKey:] + 87 5 UIKit 0x00000001077fbe8a -[UIRuntimeOutletConnection connect] + 109 6 CoreFoundation 0x000000010a210e8d -[NSArray makeObjectsPerformSelector:] + 317 7 UIKit 0x00000001077fa834 -[UINib instantiateWithOwner:options:] + 1856 8 UIKit 0x00000001075150d7 -[UIViewController _loadViewFromNibNamed:bundle:] + 383 9 UIKit 0x0000000107515a04 -[UIViewController loadView] + 177 10 UIKit 0x0000000107515d21 -[UIViewController loadViewIfRequired] + 175 11 UIKit 0x000000010755d20c -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 68 12 UIKit 0x000000010755d4ea -[UINavigationController _startTransition:fromViewController:toViewController:] + 136 13 UIKit 0x000000010755e61e -[UINavigationController _startDeferredTransitionIfNeeded:] + 870 14 UIKit 0x000000010755f86c -[UINavigationController __viewWillLayoutSubviews] + 150 15 UIKit 0x00000001077b7d0b -[UILayoutContainerView layoutSubviews] + 231 16 UIKit 0x00000001074417a8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1515 17 QuartzCore 0x000000010d94e456 -[CALayer layoutSublayers] + 177 18 QuartzCore 0x000000010d952667 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 395 19 QuartzCore 0x000000010d8d90fb _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 343 20 QuartzCore 0x000000010d90679c _ZN2CA11Transaction6commitEv + 568 21 UIKit 0x000000010738c269 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 141 22 CoreFoundation 0x000000010a210b0c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12 23 CoreFoundation 0x000000010a1f52db __CFRunLoopDoBlocks + 331 24 CoreFoundation 0x000000010a1f4a84 __CFRunLoopRun + 1284 25 CoreFoundation 0x000000010a1f430b CFRunLoopRunSpecific + 635 26 GraphicsServices 0x000000010cad7a73 GSEventRunModal + 62 27 UIKit 0x0000000107372057 UIApplicationMain + 159 28 matsumoto 0x000000010569f3a7 main + 55 29 libdyld.dylib 0x000000010b3a5955 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

様々な方法を試してみましたが、解決しません。
コード自体に問題があるのでしょうか?
ご指摘があれば、どうかよろしくお願いします。

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

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

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

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

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

guest

回答1

0

ベストアンサー

signal SIGABRT はそこまで重要ではありません。デバッグ欄で「reason」を探してください。

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<matsumoto.KoziroViewController 0x7fa669c11020> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key DrugKoziro.'

https://qiita.com/Atsushi_/items/f7930dd00a2c2ea464cd ググるとこちらのQiitaが出てきました。StoryboardからIBOutletやIBActionをつないだり消したりしませんでしたか。

投稿2019/12/13 09:47

thyda.eiqau

総合スコア2982

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

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

amam.jamjam

2019/12/14 10:55

ご丁寧に教えていただきありがとうございました。 SEGUEのつなぎ方に問題があったようで、無事解決することができました。 ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問