我设法让用户在点击按钮时从他的图库中选择图像,但是当用户选择图像时如何移动到下一个视图?
这是我从图库中选择图片的代码
@IBAction func gallery(sender: AnyObject) {
var image = UIImagePickerController()
//image.delegate = self
image.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
image.allowsEditing = false
self.presentViewController(image, animated: true, completion: nil)
}
当我拿出评论时,错误显示
cannot assign a value of type 'postChoices' to a value of type 'protocol<UIImagePickerControllerDelegate>?
我在这里尝试做的是在从图库中选择图片并在另一个视图中查看图片时转到下一个视图
答案 0 :(得分:0)
//Add Delegate to ur View Controller UIImagePickerControllerDelegate
class ViewController: UIViewController, UIImagePickerControllerDelegate
//Create Variable
var controller: UIImagePickerController?
//Delegate Methods
func imagePickerControllerDidCancel(picker: UIImagePickerController!) {
println("Picker was cancelled")
picker.dismissViewControllerAnimated(true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController!,
didFinishPickingMediaWithInfo info: [NSObject : AnyObject]!){
println("Picker returned successfully")
}
//并且View确实加载了方法
controller = UIImagePickerController()
if let theController = controller{
theController.delegate = self
theController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
theController.allowsEditing = false
presentViewController(theController, animated: true, completion: nil)