我在班上把“抄送”列为第一名。
现在,当我在IBAction中更改imagePicked的值时,如下所示:
import UIKit
类ViewController:UIViewController、UIImagePickerControllerDelegate、UINavigationControllerDelegate{
@IBOutlet weak var titelbild: UIButton!
@IBOutlet weak var profilbild: UIButton!
let imagePicker = UIImagePickerController()
var imagePicked = 0
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self
// imagePicker.allowsEditing = false
// imagePicker.sourceType = .PhotoLibrary
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func titelbildtapped(sender: AnyObject) {
// if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary){
imagePicked == 1
imagePicker.allowsEditing = false
imagePicker.sourceType = .PhotoLibrary
self.presentViewController(imagePicker, animated: true, completion: nil)
// }
}
@IBAction func profilbildtapped(sender: AnyObject) {
imagePicked == 2
imagePicker.allowsEditing = false
imagePicker.sourceType = .PhotoLibrary
self.presentViewController(imagePicker, animated: true, completion: nil)
print ("output")
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
if imagePicked == 1 {
titelbild.setImage(pickedImage, forState: UIControlState.Normal)
// titelbild.imageView?.image = pickedImage
} else if imagePicked == 2 {
profilbild.setImage(pickedImage, forState: .Normal) }
}
dismissViewControllerAnimated(true, completion: nil)
}
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
dismissViewControllerAnimated(true, completion: nil)
}
}
imagePicked的值似乎仍为0而不是2。我怎样才能改变它的值,这样它不仅在我改变它的函数中改变了?
最佳答案
好 啊。问题出在titelbildtapped
/profilbildtapped
函数中。在这里,您必须使用single=而不是double==来指定值1/2,这将检查相等性。
因此,在这些函数中将imagePicked == 1
/imagePicked == 2
更改为imagePicked = 1
/imagePicked = 2
,它应该可以工作!