select照片返回空白的用户界面

我正在尝试在我的iOS应用上制作图片上传器。

编辑7

这个问题现在更清晰地问到这里: 现在模式为图像select擦除用户界面

编辑完7

我想要做的第一件事是让用户select一个他们想要上传的图片。

编辑6

我简化了所有的代码,只需按一下button。 模态演示文稿将删除上一页的用户界面。 我如何防止这一点。

import UIKit class AddImageToStandViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() } @IBAction func loadImageButtonTapped(sender: UIButton) { let imagePicker = UIImagePickerController() imagePicker.allowsEditing = false imagePicker.sourceType = .PhotoLibrary self.presentViewController(imagePicker, animated: true, completion: nil) } } 

我发现,select工作得很好,并不会破坏用户界面,如果我推/从这个控制器不同。

编辑结束6

下面是我之前尝试的其他方法

到目前为止,该代码使用户能够按下button并从他们的照片中select照片。 但是,他们点击照片后,只是将它们返回到一个空的视图,除了底部的导航栏。

看起来我的用户正在退回,而不是他们来自的观点,而是一个单独的空视图。 我如何将用户返回到他们来自的视图?

 import UIKit class CreateStandViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { @IBOutlet var image: UIImageView! ... @IBAction func selectPicture(sender: AnyObject) { let ImagePicker = UIImagePickerController() ImagePicker.delegate = self ImagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary self.presentViewController(ImagePicker, animated: true, completion: nil) } func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { image.image = info[UIImagePickerControllerOriginalImage] as? UIImage self.dismissViewControllerAnimated(true, completion: nil) } ... 

让我知道,如果有更多的信息,我应该给。

编辑1

这个代码有相同的效果

 func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { image.image = info[UIImagePickerControllerOriginalImage] as? UIImage picker.dismissViewControllerAnimated(true, completion: nil) } 

我已经尝试添加下面的这一行,但我得到一个错误,说明CreateStandViewController.Type不能转换为预期的UIViewController

 self.presentViewController(CreateStandViewController, animated: true, completion: nil) 

编辑2

下面的代码没有错误,但也没有改变

  let createStandController = CreateStandViewController() self.presentViewController(createStandController, animated: true, completion: nil) 

编辑3

我已经从字面上复制了从这里的所有代码: http : //www.codingexplorer.com/choosing-images-with-uiimagepickercontroller-in-swift/现在有:

 import UIKit class CreateStandViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { @IBOutlet var imageView: UIImageView! let imagePicker = UIImagePickerController() @IBAction func loadImageButtonTapped(sender: UIButton) { imagePicker.allowsEditing = false imagePicker.sourceType = .PhotoLibrary presentViewController(imagePicker, animated: true, completion: nil) } override func viewDidLoad() { super.viewDidLoad() imagePicker.delegate = self } // MARK: - UIImagePickerControllerDelegate Methods func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage { imageView.contentMode = .ScaleAspectFit imageView.image = pickedImage } dismissViewControllerAnimated(true, completion: nil) } func imagePickerControllerDidCancel(picker: UIImagePickerController) { dismissViewControllerAnimated(true, completion: nil) } } 

这和以前一样。 当图像被选中时,我被发回到一个白色的视图,在底部的导航栏。

编辑4

我作为一个独立的视图控制器在它自己的单独的项目中运行相同的代码,它的工作原理。 我的应用程序的背景中有一些代码正在破坏代码的function(也许)。 我猜测它可能与导航栏有关?

编辑5

我通过select一个礼物的图像select视图去除底部的标签栏,但是没有效果。

只要更换你的

 self.dismissViewControllerAnimated(true, completion: nil) 

 picker.dismissViewControllerAnimated(true, completion: nil) 

我想你会在那之后得到这个观点的