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

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

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

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

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

Swift

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

Q&A

解決済

1回答

3319閲覧

Thread 1:signal SIGABRTって何?

退会済みユーザー

退会済みユーザー

総合スコア0

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

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

Swift

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

0グッド

1クリップ

投稿2017/07/17 16:21

編集2017/07/17 16:22

swift

1import UIKit 2 3class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource,UITextFieldDelegate{ 4 5 6 7 8 @IBOutlet weak var getUpTimeTextField: UITextField! 9 var getUpTimeDatePicker: UIDatePicker! 10 var gerUpTimeDatePickerView: UIPickerView = UIPickerView() 11 12 13 @IBOutlet weak var sexTextField: UITextField! 14 var sexPickerView: UIPickerView = UIPickerView() 15 let sexList = ["男","女"] 16 17 override func viewDidLoad() { 18 super.viewDidLoad() 19 20 getUpTimeTextField.placeholder = dateToString(date: Date()) //<-`dateToString`のパラメータは`Date`型なので最初から`Date()`を渡す 21 getUpTimeTextField.text = dateToString(date: Date()) //<-同上 22 self.view.addSubview(getUpTimeTextField) 23 getUpTimeDatePicker = UIDatePicker() 24 getUpTimeDatePicker.addTarget(self, action: #selector(changedDateEvent), for: UIControlEvents.valueChanged) 25 getUpTimeDatePicker.datePickerMode = UIDatePickerMode.time 26 getUpTimeTextField.inputView = getUpTimeDatePicker 27 28 let getUpTimeToolbar = UIToolbar(frame: CGRectMake(0, 0, 0, 35)) 29 let doneItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(ViewController.done)) 30 getUpTimeToolbar.setItems([doneItem], animated: true) 31 32 self.getUpTimeTextField.inputView = getUpTimeTextField 33 self.getUpTimeTextField.inputAccessoryView = getUpTimeToolbar 34 getUpTimeToolbar.backgroundColor = UIColor.gray 35 36 37 sexPickerView.delegate = self 38 sexPickerView.dataSource = self 39 sexPickerView.showsSelectionIndicator = true 40 self.sexTextField.text = sexList[0] 41 let sextoolbar = UIToolbar(frame: CGRectMake(0, 0, 0, 35)) 42 sextoolbar.setItems([doneItem], animated: true) 43 44 self.sexTextField.inputView = sexPickerView 45 self.sexTextField.inputAccessoryView = sextoolbar 46 sextoolbar.backgroundColor = UIColor.gray 47 } 48 49 func numberOfComponents(in pickerView: UIPickerView) -> Int { 50 return 1 51 } 52 53 func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 54 return sexList.count 55 } 56 57 func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { 58 return sexList[row] 59 } 60 61 func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { 62 self.sexTextField.text = sexList[row] 63 } 64 65 func done() { 66 self.sexTextField.endEditing(true) 67 //self.testlabel.text = self.textField.text 68 } 69 70 func CGRectMake(_ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) -> CGRect { 71 return CGRect(x: x, y: y, width: width, height: height) 72 } 73 74 75 override func didReceiveMemoryWarning() { 76 super.didReceiveMemoryWarning() 77 } 78 79 func changeLabelDate(date: Date) { //<- `NSDate`を使っているところは全て`Date`に置き換える 80 getUpTimeTextField.text = self.dateToString(date: date) 81 } 82 83 84 func dateToString(date: Date) -> String { 85 //DateFormatterは参照型なので、letが適切 86 let date_formatter = DateFormatter() 87 //曜日の1文字表記をしたいならweekdaysなんて配列はいらない 88 89 date_formatter.locale = Locale(identifier: "ja") 90 date_formatter.dateFormat = "hh時間mm分 " 91 return date_formatter.string(from: date as Date) 92 } 93 94 func changedDateEvent(_ sender: UIDatePicker){ //<- `UIDatePicker`からのactionの`sender`は必ず`UIDatePicker`になる 95 //`sender`を直接`UIDatePicker`として使えばいいのでキャストは不要 96 self.changeLabelDate(date: sender.date) 97 } 98 // Dispose of any resources that can be recreated. 99 100} 101 102

これを実行した結果次のようなエラーが出ました。
時間の方のtextFieldをタップすると落ちます。
なぜエラーが出るのかわかりません。教えてください

以下がエラーコードです

2017-07-18 01:13:24.598936+0900 label2[2005:679534] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-07-18 01:13:24.599416+0900 label2[2005:679534] [MC] Reading from public effective user settings.
2017-07-18 01:13:24.653404+0900 label2[2005:679534] *** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<UICompatibilityInputViewController: 0x100b35080> should have parent view controller:<label2.ViewController: 0x100b08890> but requested parent is:<UIInputWindowController: 0x1010c7200>'
*** First throw call stack:
(0x181afafe0 0x18055c538 0x181afaf28 0x187cc6728 0x1886178c0 0x1886189e4 0x187c39d20 0x188618758 0x188611494 0x187cf0d5c 0x187c51d44 0x187caf550 0x187caf8c0 0x187d30834 0x187dd5e58 0x187dd5368 0x1881fdd38 0x18820156c 0x187dbb470 0x187c5d380 0x1881f1810 0x1881f13e0 0x1881f068c 0x187c5b70c 0x187c2c33c 0x188426014 0x188420770 0x188420b9c 0x181aa942c 0x181aa8d9c 0x181aa69a8 0x1819d6da4 0x183440074 0x187c91058 0x1000149ac 0x1809e559c)
libc++abi.dylib: terminating with uncaught exception of type NSException

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

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

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

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

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

guest

回答1

0

ベストアンサー

View の階層関係が壊れてしまっているエラー内容になります。
下記コードで inputViewTextField を設定しているのが原因です。

swift

1 self.getUpTimeTextField.inputView = getUpTimeTextField

また、このスコープでの getUpTimeTextField へのアクセスに self は不要なので削除した方が見やすいかと思います。

以下のコードも上記と同じ getUpTimeTextField を指していることになります。

swift

1 getUpTimeTextField.inputView = getUpTimeDatePicker

投稿2017/07/18 13:14

ykws

総合スコア1236

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問