前提・実現したいこと
アプリ内で登録したプロフィール画像、名前、レート、ボタンの状態などをUserDefaultsに保存しておきたいです。
発生している問題・エラーメッセージ
Value of type 'UIImage' has no member 'image'
importからviewDidLoadまで
Swift
1import UIKit 2import Photos 3 4class ProfViewController: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITextFieldDelegate { 5 6 @IBOutlet var icon2: UIImageView! 7 @IBOutlet var userNameTextField2: UITextField! 8 @IBOutlet var textField2: UITextField! 9 @IBOutlet var registerBT2: UIButton! 10 @IBOutlet var LINEButton2: UIButton! 11 @IBOutlet var TwitterButton2: UIButton! 12 @IBOutlet var FBButton2: UIButton! 13 @IBOutlet var InstaButton2: UIButton! 14 @IBOutlet var DiscordButton2: UIButton! 15 @IBOutlet var SlackButton2: UIButton! 16 @IBOutlet var TextBox2: UITextView! 17 18 var userNameTextField = String() 19 var textField = String() 20 var icon = UIImage() 21 22 var TWunchecked: UIImage = UIImage(named: "twitter-gray")! 23 var TWchecked: UIImage = UIImage(named: "twitter")! 24 var Lunchecked: UIImage = UIImage(named: "LINE-gray")! 25 var Lchecked: UIImage = UIImage(named: "LINE")! 26 var FBunchecked: UIImage = UIImage(named: "facebook-gray")! 27 var FBchecked: UIImage = UIImage(named: "facebook")! 28 var Iunchecked: UIImage = UIImage(named: "Instagram-gray")! 29 var Ichecked: UIImage = UIImage(named: "Instagram")! 30 var Dunchecked: UIImage = UIImage(named: "Discord-gray")! 31 var Dchecked: UIImage = UIImage(named: "Discord")! 32 var Sunchecked: UIImage = UIImage(named: "Slack-gray")! 33 var Schecked: UIImage = UIImage(named: "Slack")! 34 35 var flg = false 36 let userDefaults = UserDefaults.standard 37 38 override func viewDidLoad() { 39 super.viewDidLoad() 40 41 userNameTextField2.text = userNameTextField 42 textField2.text = textField 43 icon2.image = icon 44 45 TextBox2.layer.borderWidth = 2.0; 46 TextBox2.layer.borderColor = UIColor.lightGray.cgColor 47 TextBox2.layer.cornerRadius = 5.0 48 49 userNameTextField2.delegate = self 50 textField2.delegate = self 51 52 //角丸系 53 registerBT2.layer.cornerRadius = 5.0 54 userNameTextField2.layer.cornerRadius = 5.0 55 56 57 } 58 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 59 textField2.resignFirstResponder() 60 } 61 62 @IBAction func iconChange2(_ sender: Any) { 63 64 //アルバムの呼び出し 65 PHPhotoLibrary.requestAuthorization { (status) in 66 switch(status){ 67 case .authorized: 68 print("許可されています。") 69 70 case .denied: 71 print("拒否された。") 72 73 case .notDetermined: 74 print("notDetermined") 75 76 case .restricted: 77 print("restricted") 78 @unknown default: break 79 //@unknown default:追加しろって言われたからbreak入れた 80 } 81 } 82 83 let sourceType = UIImagePickerController.SourceType.photoLibrary 84 85 if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){ 86 87 let cameraPicker = UIImagePickerController() 88 cameraPicker.sourceType = sourceType 89 cameraPicker.delegate = self 90 cameraPicker.allowsEditing = true 91 present(cameraPicker, animated: true, completion: nil) 92 93 }else{ 94 95 print("error") 96 97 } 98 99 } 100 101 func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { 102 103 if let pickedImage = info[.editedImage] as? UIImage{ 104 105 let imagedata = UIImageJPEGRepresentation(pickedImage.image, 1); 106 UserDefaults.standardUserDefaults().setObject(imagedata, forKey: "pickedImage") 107 UserDefaults.standard.synchronize() 108 109 icon2.image = pickedImage 110 picker.dismiss(animated: true, completion: nil) 111 } 112 113 } 114 115 func textFieldShouldReturn(_ textField: UITextField) -> Bool { 116 textField2.resignFirstResponder() 117 return true 118 } 119
試したこと
ツールのバージョン
Xcode : Version 10.3 (10G8)
Swift : Apple Swift version 5.0.1
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/09/07 13:08