前提・実現したいこと
Swiftで自分の指定した色をUITextFieldに書かれると次の画面にその色がバックグランドカラーで表示されるものを作っています。
そこで、UITextFieldに書かれたもの(例:赤、あか、レッド、red)を定義した1つの番号に変えるようにしたい。
その番号を次の画面にsegueで値を渡したい
<追記>
定義の仕方が分からなく、書き方がわからない状況にあります
どこに何を書いたら教えていただきたいです。
該当のソースコード
swift
1import UIKit 2import Foundation 3 4class ViewController: UIViewController, UITextFieldDelegate { 5 6@IBOutlet weak var selectcolor: UITextField! 7 8@IBAction func didTapSelectColorButton(_ sender: Any) { 9 // 空なら遷移させない 10 if selectcolor.text == "" { 11 let alert = UIAlertController(title: "入力エラー", message: "条件にある色を指定してください", preferredStyle: .alert) 12 alert.addAction(UIAlertAction(title:"OK",style: .default)) 13 self.present(alert, animated: true, completion: nil) 14 }else{ 15 performSegue(withIdentifier: "toSecond", sender: nil) 16 } 17 } 18 19 //画面遷移時の処理 20 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 21 let colorController = segue.destination as! ColorController 22 colorController.text1 = selectcolor.text 23 } 24} 25
補足情報
勉強し始めでわからないことだらけで、ここに初めて投稿させてもらうので、説明が不足している部分もあると思いますが、お願いします。
現在のコードで何が問題なのか書いて下さい。
回答1件
あなたの回答
tips
プレビュー