使用未解析的标识符'imageFromCameraRoll'

时间:2017-06-08 02:50:52

标签: swift xcode

我收到错误,使用未解析的标识符'imageFromCameraRoll'。现在我正在建立一个系统,我可以在我的应用程序中访问相机胶卷。 我在SendController中写过像

import Foundation
import UIKit
class SendController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

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


        if didFinishPickingMediaWithInfo[UIImagePickerControllerOriginalImage] != nil {
            imageFromCameraRoll.image = didFinishPickingMediaWithInfo[UIImagePickerControllerOriginalImage] as? UIImage


        }

        picker.dismiss(animated: true, completion: nil)
    }

}

我在PhotoSendController中写过

import UIKit

class PhotoSendController:UIViewController,
UINavigationControllerDelegate,UIImagePickerControllerDelegate{
    @IBAction func ButtonCamera(_ sender: UIButton) {
                    openPicker(sourceType: UIImagePickerControllerSourceType.photoLibrary)

    }


    @IBAction func pressCameraRoll(_ sender: Any) {
        pickImageFromLibrary() 
    }

    @IBOutlet weak var imageFromCameraRoll: UIImageView!

    //定数
    let ButtonCamera = 0
    let ButtomRead = 1
    let ButtonWrite = 2


    //変数
    var imageView:UIImageView  = UIImageView()
    var btnCamera:UIButton = UIButton(type: .custom)
    var btnRead:UIButton  = UIButton(type: .custom)
    var btnWrite:UIButton  = UIButton(type: .custom)

    override func viewDidLoad() {
        super.viewDidLoad()

    }
       func onClick(sender:UIButton){
       if sender.tag == ButtonCamera {
          showAlert(title: nil, text: "利用できません")
          openPicker(sourceType: UIImagePickerControllerSourceType.camera)


         }else if sender.tag == ButtomRead {
           openPicker(sourceType: UIImagePickerControllerSourceType.photoLibrary)
        }

    }

    func showAlert(title: String?, text: String?) {
        let alert = UIAlertController(title: title, message: text, preferredStyle: UIAlertControllerStyle.alert)
        alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
        present(alert, animated: true, completion: nil)
    }

    func openPicker(sourceType:UIImagePickerControllerSourceType){
        if !UIImagePickerController.isSourceTypeAvailable(sourceType){
            showAlert(title: nil, text: "利用できません")
            return
        }

        let picker = UIImagePickerController()
        picker.sourceType = sourceType
        picker.delegate = self
        present(picker, animated: true, completion: nil)
           }

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        let image = info[UIImagePickerControllerOriginalImage]as! UIImage
        imageView.image = image
        picker.presentingViewController?.dismiss(animated: true,completion:nil)
    }

    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        picker.presentingViewController?.dismiss(animated: true, completion: nil)
    }

    func pickImageFromLibrary() {

        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) { 
            let controller = UIImagePickerController()
            controller.delegate = self
            controller.sourceType = UIImagePickerControllerSourceType.photoLibrary
            self.present(controller, animated: true, completion: nil)
        }
    }
}

首先,我以为我在PhotoSendController中写了@IBOutlet weak var imageFromCameraRoll: UIImageView!,但我无法选择UIImageView并按下控制键并拖放PhotoSendController(通常我可以这样做同样的事情)但是这次我不能这样做,因为没有显示粘贴到Controller的蓝线。我的代码中发生了什么?为什么没有显示蓝线?我能解决这个问题吗?

0 个答案:

没有答案