我设法让用户在单击按钮时从他的图库中选择一个图像,但是当用户选择一个图像时,我如何移动到下一个视图?
下面是我从图库中选择图像的代码
@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>?
我在这里尝试做的是,当从图库中选择一张图片时,转到下一个视图,并在另一个视图中查看它
发布于 2015-05-19 07:52:14
//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 did load方法
controller = UIImagePickerController()
if let theController = controller{
theController.delegate = self
theController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
theController.allowsEditing = false
presentViewController(theController, animated: true, completion: nil)
https://stackoverflow.com/questions/30319623
复制