「世界一受けたい iPhoneアプリ開発の授業 Chapter7-2
四択検定アプリを作ろう」を参考にして問題に○ x イメージを付ける方法は成功し次問にも移れたのですが、アクションボタンの形状を作り直したらすべての問題でXが表示されます。
ここでマイクボタンを押して こんにちは と音読すると橙色のテキストビューに こんにちは と表示されます。そこで、左の判定ボタンを押すと○印が表示される仕掛けです。正常に○ X が表示されていました。
###問題の症状
しかし、StackViewに入れた4個のボタンの形状・色が好ましくなくないので、一旦削除してつくり直しました。そうしたら、正しい回答を入れても X が表示されるようになってしまいました。
他の3つのボタンはボタン交換前と同じように正常に機能します。
###やった対策
Xcodeのクリーン
DerivedData フォルダの削除
Xcodeの終了、
Macの再起動
iPhone実機のアプリ削除
iPhoneの再起動
ImageViewの削除と再作成
すべての@IBOutlet の削除とストーリーボードよりの作成・リンク
3つの@IBAction func の削除とストーリーボードよりの作成・リンク
○とXのイメージをXcodeから削除して再度インポート
###関係ファイルのコード
// MondaiViewController.swift // Lesson01 // // import UIKit class MondaiViewController: UIViewController, UITextViewDelegate { //bitbucket練習用変更 音声問題.csvファイルを格納する配列csvArray @IBOutlet weak var mondaiNumberLabel: UILabel! @IBOutlet weak var mondaiView: UITextView! @IBOutlet weak var kaitouView: UITextView! @IBOutlet weak var judgeImageView: UIImageView! @IBOutlet weak var hantei: UIButton! @IBOutlet weak var yarinaoshi: UIButton! @IBOutlet weak var tsugino: UIButton! @IBOutlet weak var skip: UIButton! //"OnseiTextsCSV"ファイルを格納する配列csvArray var csvArray:[String] = [] //csvArrayから取り出した問題を格納する配列mondaiArray var mondaiArray:[String] = [] var mondaiCount = 0 //問題をカウントする変数 var correctCount = 0 //正解をカウントする変数 let total = 10 //出題数を管理する変数 var nextBtn = UIButton() override func viewDidLoad() { super.viewDidLoad() print ("ここまで来たaaa") let viewController = GameStartViewController() //loadCSVメソッドを使用し、csvArrayに検定問題を格納 csvArray = viewController.loadCSV("OnseiTextsCSV") //csvArrayの0行目を取り出し、カンマを区切りとしてmondaiArrayに格納 mondaiArray = csvArray[mondaiCount].components(separatedBy: ",") //変数mondaiCountに1を足して、ラベルに出題数を設定 mondaiNumberLabel.text = "第\(mondaiCount+1)問" //TextViewに問題を設定 mondaiView.text = mondaiArray[0] //テキストビューに自動でキーボード表示 kaitouView.becomeFirstResponder() // Delegate を設定 kaitouView.delegate = self // プレースホルダー //kaitouView.placeholder = "マイクで読む" } //判定ボタンをタップした時の回答正誤の判定と○X表示 @IBAction func btnAction(_ sender: UIButton) { print ("ここまで来たbbb") if mondaiView.text == kaitouView.text { //○を表示 judgeImageView.image = UIImage(named: "maru.png") print ("ここまで来たccc") //正解カウントを増やす correctCount += 1 }else{ //間違っていたら×を表示 print ("ここまで来たddd") judgeImageView.image = UIImage(named: "batsu.png") print ("ここまで来たeee") } //回答ボタンの使用停止 hantei.isEnabled = false } //やり直しボタンを押したときの動作 @IBAction func btn02Action(_ sender: UIButton) { print ("ここまで来たfff") //回答欄を空に kaitouView.text = nil } //次の問題問題を押した時の動作⇒問題数を+1、csvファイルより次の問題を転写⇒10問過ぎたら得点画面に遷移 字数制限のため以下省略 }
###if文のロジック
下記のif文で判定をしています。
mondaiView.text はOnseiTextsCSV.csv で呼び込んでいます。
記述内容を単純な 1 と記載して試しましたが症状は変わりません。
@IBAction func btnAction(_ sender: UIButton) { print ("ここまで来たbbb") if mondaiView.text == kaitouView.text { //○を表示 judgeImageView.image = UIImage(named: "maru.png") print ("ここまで来たccc") //正解カウントを増やす correctCount += 1 }else{ //間違っていたら×を表示 print ("ここまで来たddd") judgeImageView.image = UIImage(named: "batsu.png") print ("ここまで来たeee") }
###Printによるコード上の推移
print ("ここまで来たaaa")から print ("ここまで来たLLL")までを配置してアプリを起動後、最初の 判定ボタン をタップしますと、下記のとおり表示されます。つまり、「ここまで来たddd」と表示されてif文は x 判定になっています。
objc[4431]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x11815acc0) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x117f716f0). One of the two will be used. Which one is undefined. ここまで来た01 ここまで来た02 ここまで来た01 2017-08-23 15:15:25.239820+0900 Lesson01Pay[4431:1006599] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "<_UILayoutSupportConstraint:0x608000097a20 _UILayoutGuide:0x7fa8e3d06060.height == 64 (active)>", "<_UILayoutSupportConstraint:0x608000094370 V:|-(0)-[_UILayoutGuide:0x7fa8e3d06060] (active, names: '|':UIView:0x7fa8e3d08480 )>", "<_UILayoutSupportConstraint:0x608000096e90 _UILayoutGuide:0x7fa8e3d0e2b0.height == 49 (active)>", "<_UILayoutSupportConstraint:0x6080000987e0 _UILayoutGuide:0x7fa8e3d0e2b0.bottom == UIView:0x7fa8e3d08480.bottom (active)>", "<NSLayoutConstraint:0x60000009c890 UIButton:0x7fa8e3c13870'\U30b9\U30bf\U30fc\U30c8'.height == 39 (active)>", "<NSLayoutConstraint:0x60000009d060 UITextView:0x7fa8e4022600'\U30b9\U30bf\U30fc\U30c8\U30dc\U30bf\U30f3\U306b\U89e6\U308b\U3068\U554f\U984c\U3068\U56de\U7b54\U6b04\U304c\U73fe\U308c\U307e\U3059\U3002\U5de6\U4e0b...'.height >= 150 (active)>", "<NSLayoutConstraint:0x608000097700 V:[_UILayoutGuide:0x7fa8e3d06060]-(30)-[UILabel:0x7fa8e3c19fa0'\U30b2\U30fc\U30e0\U3092\U59cb\U3081\U307e\U3057\U3087\U3046'] (active)>", "<NSLayoutConstraint:0x608000097e80 V:[UILabel:0x7fa8e3c19fa0'\U30b2\U30fc\U30e0\U3092\U59cb\U3081\U307e\U3057\U3087\U3046']-(8)-[UITextView:0x7fa8e4022600'\U30b9\U30bf\U30fc\U30c8\U30dc\U30bf\U30f3\U306b\U89e6\U308b\U3068\U554f\U984c\U3068\U56de\U7b54\U6b04\U304c\U73fe\U308c\U307e\U3059\U3002\U5de6\U4e0b...'] (active)>", "<NSLayoutConstraint:0x608000098dd0 V:[UITextView:0x7fa8e4022600'\U30b9\U30bf\U30fc\U30c8\U30dc\U30bf\U30f3\U306b\U89e6\U308b\U3068\U554f\U984c\U3068\U56de\U7b54\U6b04\U304c\U73fe\U308c\U307e\U3059\U3002\U5de6\U4e0b...']-(72)-[UIButton:0x7fa8e3c13870'\U30b9\U30bf\U30fc\U30c8'] (active)>", "<NSLayoutConstraint:0x608000099410 V:[UIButton:0x7fa8e3c13870'\U30b9\U30bf\U30fc\U30c8']-(224)-[_UILayoutGuide:0x7fa8e3d0e2b0] (active)>", "<NSLayoutConstraint:0x61000009ea50 'UIView-Encapsulated-Layout-Height' UIView:0x7fa8e3d08480.height == 568 (active)>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x60000009d060 UITextView:0x7fa8e4022600'スタートボタンに触ると問題と回答欄が現れます。左下...'.height >= 150 (active)> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 2017-08-23 15:15:26.635 Lesson01Pay[4431:1006599] Failed to set (clipsToBounds) user defined inspected property on (Lesson01Pay.MondaiViewController): [<Lesson01Pay.MondaiViewController 0x7fa8e3e460d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key clipsToBounds. 2017-08-23 15:15:26.636 Lesson01Pay[4431:1006599] Failed to set (clipsToBounds) user defined inspected property on (Lesson01Pay.MondaiViewController): [<Lesson01Pay.MondaiViewController 0x7fa8e3e460d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key clipsToBounds. ここまで来たaaa ここまで来た02 ここまで来た01 2017-08-23 15:15:26.664227+0900 Lesson01Pay[4431:1006599] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/tomijisuzuki/Library/Developer/CoreSimulator/Devices/A5E1F1E7-7B0A-49E2-AC08-78240DC82579/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 2017-08-23 15:15:26.664586+0900 Lesson01Pay[4431:1006599] [MC] Reading from private effective user settings. ここまで来たfff ここまで来たbbb ここまで来たddd ここまで来たeee
以上が問題の概要ですが、あとはどこをチェックしたらよいでしょうか。ご教示ください。
開発環境は下記のとおりです。
MacBookPro
OS-X10.12.6 Sierra
Xcode 8.3.3 (8E3004b)
よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/24 01:36