我编写了一个函数,它将枚举值作为参数。我没有得到函数原型的任何错误,但是一旦我尝试将该函数调用为一个块,就会得到一个错误,说“使用未解析的标识符”:
@IBAction func addButtonPressed(sender: AnyObject) {
let actionMenu = UIAlertController(title: "Take a Photo or choose an
existing one", message: nil, preferredStyle:
UIAlertControllerStyle.ActionSheet)
let takePhotoAction = UIAlertAction(title: "take Photo", style: UIAlertActionStyle.Default, handler: {(alert: UIAlertAction!) -> Void in
println("take Photo")
})
let choosePhotoAction = UIAlertAction(title: "choose an existing Photo", style: UIAlertActionStyle.Default, handler: {(alert: UIAlertAction!) -> Void in
println("choose Photo")
//getting error right here
self.displayPickerController(UIImagerPickerControllerSourceType.PhotoLibrary)
})
actionMenu.addAction(takePhotoAction)
actionMenu.addAction(choosePhotoAction)
presentViewController(actionMenu, animated: true, completion: nil)
}
// MARK: - Helper Methods
func displayPickerController(withSource: UIImagePickerControllerSourceType){
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = withSource
presentViewController(imagePicker, animated: true, completion: nil)
}
答案 0 :(得分:0)
self.displayPickerController(UIImagerPickerControllerSourceType.PhotoLibrary)
中有拼写错误。在命名枚举时,您键入了UIImager
而不是UIImage
。