質問編集履歴
1
実装できたコードを記載
test
CHANGED
File without changes
|
test
CHANGED
@@ -119,3 +119,91 @@
|
|
119
119
|
}
|
120
120
|
|
121
121
|
```
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
最終的に下記のようになりました。
|
132
|
+
|
133
|
+
```swift
|
134
|
+
|
135
|
+
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
// 選択した画像・写真を取得し、imageViewに表示
|
140
|
+
|
141
|
+
if let info = editingInfo, let editedImage = info[UIImagePickerControllerEditedImage] as? UIImage{
|
142
|
+
|
143
|
+
ProfileImage.image = editedImage
|
144
|
+
|
145
|
+
}else{
|
146
|
+
|
147
|
+
ProfileImage.image = image
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
// UIImage => NSDataに変換してUserDefaultに保存
|
154
|
+
|
155
|
+
let imageData = UIImageJPEGRepresentation(ProfileImage.image!, 1);
|
156
|
+
|
157
|
+
NSUserDefaults.standardUserDefaults().setObject(imageData, forKey: "myImage")
|
158
|
+
|
159
|
+
NSUserDefaults.standardUserDefaults().synchronize()
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
// フォトライブラリの画像・写真選択画面を閉じる
|
164
|
+
|
165
|
+
picker.dismissViewControllerAnimated(true, completion: nil)
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
```
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
```swift
|
176
|
+
|
177
|
+
// 画面が表示されたときのアクション
|
178
|
+
|
179
|
+
override func viewWillAppear(animated: Bool) {
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
// NSUserDefaultsクラスを呼び出す
|
184
|
+
|
185
|
+
//standardUserDefaults():ユーザーデフォルトを準備
|
186
|
+
|
187
|
+
let profile = NSUserDefaults.standardUserDefaults()
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
// stringForKey:データを読み込む
|
192
|
+
|
193
|
+
let myData = profile.stringForKey("myName")
|
194
|
+
|
195
|
+
let myDataSex = profile.stringForKey("mySex")
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
if let imageData = profile.objectForKey("myImage") as? NSData, image = UIImage(data: imageData) {
|
200
|
+
|
201
|
+
// UserDefaultsから画像が取得出来た場合ImageViewのimageに設定
|
202
|
+
|
203
|
+
ProfileImage.image = image
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
```
|