我的ViewController - 我只是選擇一個圖像,然後更新imageView。儘管如此,無論何時我離開視圖,ImageView都會回到「面部未知」狀態,因爲newImage很糟糕。當視圖發生變化時,變匝數爲零
爲什麼變量newImage在視圖更改後不記得圖像?
var newImage: UIImage!
@IBOutlet weak var imageView: UIImageView!
var imagePicker = UIImagePickerController()
override func viewDidLoad() {
super.viewDidLoad()
if((newImage == nil)){
imageView.image = UIImage(named:"face-unknown")!
}else{
imageView.image = newImage
}
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let possibleImage = info["UIImagePickerControllerEditedImage"] as? UIImage {
imageView.image = resizeImage(possibleImage,newWidth: 150)
newImage = resizeImage(possibleImage,newWidth: 150)
} else if let possibleImage = info["UIImagePickerControllerOriginalImage"] as? UIImage {
imageView.image = resizeImage(possibleImage,newWidth: 150)
newImage = resizeImage(possibleImage,newWidth: 150)
} else {
return
}
這取決於你的意思是「離開視圖」。如果您在返回時創建新的視圖控制器,它不知道存儲在屬於舊控制器的變量中的內容。 –