选择照片返回空白的用户界面 [英] Selecting photo returns to blank UI

查看:190
本文介绍了选择照片返回空白的用户界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的iOS应用上制作一个图片上传器。

编辑7



现在这个问题更清楚的问到这里:目前用于图片选择擦除用户界面的模式



编辑完7



我想要做的第一件事是让用户选择一个图像想要上传。

编辑6

只需按一下按钮。模态演示文稿将删除上一页的用户界面。

 导入UIKit 

类AddImageToStandViewController:UIViewController {

重写func viewDidLoad(){
super.viewDidLoad()
}

$ b @IBAction func loadImageButtonTapped(sender:UIButton){
let imagePicker = UIImagePickerController()
imagePicker.allowsEditing = false
imagePicker.sourceType = .PhotoLibrary

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





$ b $ p
$ b

我发现选择工作得很好,销毁用户界面如果我推/从这个控制器不同的继续。



编辑6



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



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

看起来我的用户正在退回,而不是他们来自的视图,而是一个单独的空视图。

 导入UIKit 

类CreateStandViewController如何将用户返回到它们来自的视图? :UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate {


@IBOutlet var image:UIImageView!



$ b @IBAction func selectPicture(sender:AnyObject){

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)


$ b ...

让我知道是否还有更多的信息。



此代码具有相同的效果
$ b $ pre $ func imagePickerController picker:UIImagePickerController,didFinishPickingMediaWithInfo info:[String:AnyObject]){

image.image = info [UIImagePickerControllerOriginalImage] as? UIImage
picker.dismissViewControllerAnimated(true,completion:nil)

$ b}

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

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

编辑2

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

$ pre $ let $ createStandController = CreateStandViewController $ b $ self.presentViewController(createStandController,animated:


$编辑3



我从这里复制了所有的代码: http://www.codingexplor er.com/choosing-images-with-uiimagepickercontroller-in-swift/ ,现在有:

  import UIKit 

类CreateStandViewController:UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate {

@IBOutlet var imageView:UIImageView!
$ b $ imagePicker = UIImagePickerController()
$ b @IBAction func loadImageButtonTapped(sender:UIButton){
$ b $ imagePicker.allowsEditing = false
imagePicker .sourceType = .PhotoLibrary
$ b presentViewController(imagePicker,animated:true,completion:nil)
}
$ b重写func viewDidLoad(){
super。 viewDidLoad()

imagePicker.delegate = self
}

// MARK: - UIImagePickerControllerDelegate方法

func imagePickerController(picker:UIImagePickerController ,didFinishPickingMediaWithInfo信息:[字符串:AnyObject]){
如果让pickImage = info [UIImagePickerControllerOriginalImage] as? UIImage {
imageView.contentMode = .ScaleAspectFit
imageView.image = pickedImage
}

dismissViewControllerAnimated(true,completion:nil)
}

func imagePickerControllerDidCancel(picker:UIImagePickerController){
dismissViewControllerAnimated(true,completion:nil)
}

}

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



编辑4



我在独立的视图控制器中运行相同的代码,并且它可以工作。我的应用程序的背景中有一些代码正在破坏代码的功能(也许)。我猜这可能与导航栏有关吗?
$ b $编辑5


解决方案

解决方案

解决方案

>

  self.dismissViewControllerAnimated(true,completion:nil)

with

  picker.dismissViewControllerAnimated(true ,完成:无)

我想你会在那之后得到点数

I am trying to make an image uploader on my ios app.

EDIT 7

This question is now more clearly asked here: Present Modal for Image Select Erases UI

END OF EDIT 7

The first thing I am trying to do is enable the user to select an image that they want for upload.

EDIT 6

I have simplified all the code to simply one button press. The Modal presentation deletes the previous page's UI. How I prevent this.

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)

    }
}

I have found that the selection works just fine and does not destroy the UI if I push/segue from a different to this controller.

END OF EDIT 6

Below this is the other methods that I have tried before this

So far, this code enables a user to press a button and choose a photo from their photos. But, after they click the photo it just returns them to an empty View except the navbar at the bottom.

It seems my user is being returned, not to the view that they came from, but to a separate empty view. How do I return the user to the view that they came from?

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)

    }

    ...

let me know if there is any more information that I should give.

EDIT 1

this code has the same effect

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

    image.image = info[UIImagePickerControllerOriginalImage] as? UIImage
    picker.dismissViewControllerAnimated(true, completion: nil)


}

I have tried adding this line below but I get an error stating that CreateStandViewController.Type cannot be converted to the expected UIViewController.

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

EDIT 2

This code below doesnt error but also changes nothing

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

EDIT 3

I have literally copied all the code from here: http://www.codingexplorer.com/choosing-images-with-uiimagepickercontroller-in-swift/ and now have:

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)
    }

}

This has the same issue as before. When the image is selected I am sent back to a view that is white with the navbar at the bottom.

EDIT 4

I have run the same code in its own separate project as a stand alone view controller and it works. There is some code that I have in the background of my app that is killing the functionality of the code (maybe). I am guessing it may have something to do with the navbar?

EDIT 5

I removed the tab bar at the bottom by seguing to the image selecting view via a present Modally segue, but it had no effect.

解决方案

Just replace your

self.dismissViewControllerAnimated(true, completion: nil)

with

picker.dismissViewControllerAnimated(true, completion: nil)

I think you will get the point after that

这篇关于选择照片返回空白的用户界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆