使用未解析的标识符'CameraViewController'
问题描述:
我得到这个错误,我该如何解决它?使用未解析的标识符'CameraViewController'
https://www.dropbox.com/s/ipgedtenxjzsm7q/Captura%20de%20pantalla%202016-04-26%2020.07.52.png?dl=0
Use of unresolved identifier 'CameraViewController'
我使用https://cocoapods.org/pods/ALCameraViewController
代码:
import UIKit
class pantalla6: UIViewController, UIImagePickerControllerDelegate , UINavigationControllerDelegate, UICollectionViewDataSource, UICollectionViewDelegate {
// "Mes 1", "Mes 2", "Mes 3", "Mes 4", "Mes 5", "Mes 6", "Mes 7", "Mes 8", "Mes 9", "Mes 10", "Mes 11", "Mes 12"
var tableData: [String] = []
var tableImages: [UIImage] = []
var tableControl: Int = 0
var guardaImagen: UIImage?
var indexPathSelected : Int = 0
//NSUSERDEFAULTS // guardar estado
var objetoNsDefault = NSUserDefaults.standardUserDefaults()
var stringsarraydeimagenes:[String]?
var key = "keySave" //Se guarda el nombre de las imagenes en esta key
//FIN NSUSERDEFAULTS
//var CeldaSwipeada: Int = 0
override func viewDidLoad() {
super.viewDidLoad()
let croppingEnabled = true
let cameraViewController = CameraViewController(croppingEnabled: croppingEnabled) { image in
// Do something with your image here.
// If cropping is enabled this image will be the cropped version
}
presentViewController(cameraViewController, animated: true, completion: nil)
//USAR SWYPE START
//self.collectionview.cellForItemAtIndexPath(indexPathSelected).addGestureRecognizer(swipeRight)
//USAR SWYPE FIN
collectionview.delegate = self
imagePicker.delegate = self /// estableces que el delegado va estar en este viewcontroller
//RECUPERAR IMAGENES
//tableImages = NSUserDefaults.standardUserDefaults().arrayForKey("ImagenesGuardadas")
/* LO QUE YO HABIA PUESTO
if let testArray : AnyObject? = objetoNsDefault.objectForKey(key) {
var readArray : [NSString] = testArray! as! [NSString] //falta saber donde se guardar las imagenes tableImages es del tipo UIimages
}
*/
//LO QUE TU HABÍAS PUESTO
/*
let placesData = NSUserDefaults.standardUserDefaults().objectForKey("ImagenesGuardadas") as? NSData
tableImages = (NSKeyedUnarchiver.unarchiveObjectWithData(placesData!) as? [UIImage])!
*/
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {return UIInterfaceOrientation.Landscape.rawValue}
func guardardatos(){
/*LO QUE PUSISTE
let placesData = NSKeyedArchiver.archivedDataWithRootObject(tableImages)
NSUserDefaults.standardUserDefaults().setObject(placesData, forKey: "ImagenesGuardadas")
*/
//save
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setObject(stringsarraydeimagenes, forKey: key)
defaults.synchronize()
/*
NSUserDefaults.standardUserDefaults().setObject(tableImages, forKey: "ImagenesGuardadas")
NSUserDefaults.standardUserDefaults().synchronize()
*/
print("dato guardado")
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return tableData.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: colvwCell = collectionview.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! colvwCell
cell.lblCell.text = tableData[indexPath.row]
cell.imgCell.image = tableImages[indexPath.row]
/*quitando esto se ve mejor*/
cell.basurita.hidden = false
cell.imgCell.contentMode = UIViewContentMode.ScaleAspectFit
cell.basurita?.layer.setValue(indexPath.row, forKey: "index")
// cell.basurita?.addTarget(self, action: "deleteUser:", forControlEvents: UIControlEvents.TouchUpInside)
//let action = #selector(self.deleteUser)
//cell.basurita.addTarget(self, action: action, forControlEvents: .TouchUpInside)
cell.basurita?.addTarget(self, action:#selector(pantalla6.deleteUser(_:)),
forControlEvents: UIControlEvents.TouchUpInside)
/*quitando esto se ve mejor*/
// Remove the button from the first cell
/*if (indexPath.row == 0){
let close : UIButton = cell.viewWithTag(11) as! UIButton
close.hidden = true
}
*/
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
print("Cell \(indexPath.row) selected")
indexPathSelected = indexPath.row
//pantalla8fotoViewController().newImage = tableImages[indexPathSelected]
let loginPageView = self.storyboard?.instantiateViewControllerWithIdentifier("FotosID") as! pantalla8fotoViewController
loginPageView.newImage = tableImages[indexPathSelected]
self.presentViewController(loginPageView, animated: true, completion: nil)
//loginPageView.newImage = tableImages[indexPathSelected]
print("pasado")
print(indexPathSelected)
// print(loginPageView.newImage)
}
@IBOutlet weak var collectionview: UICollectionView!
@IBOutlet weak var picture: UIImageView! /// defines el UIImageView
let imagePicker = UIImagePickerController() /// defines el image Picker
@IBAction func openLibrary(sender: AnyObject) { ///accion del boton Library
imagePicker.allowsEditing = false
imagePicker.sourceType = .PhotoLibrary
presentViewController(imagePicker, animated:true, completion: nil)
}
@IBAction func openCamera(sender: AnyObject) { ///accion del boton Camara
imagePicker.allowsEditing = false
imagePicker.sourceType = .Camera
presentViewController(imagePicker, animated:true, completion: nil)
}
//Mark: delegates //// delegado del imagePicker controller que establece que una imagen fue escogida ya sea de la camara o del carrete
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
//picture.contentMode = .ScaleAspectFit
//picture.image = pickedImage
tableImages.append(pickedImage)
tableImages.insert(pickedImage, atIndex: tableControl)
tableData.append("Mes " + "\(tableControl + 1)")
//tableImages.insert(pickedImage, atIndex: tableControl)
//tableImages[tableControl] = pickedImage
//tableData[tableControl] = "Mes " + "\(tableControl + 1)"
guardaImagen = pickedImage
if (picker.sourceType == UIImagePickerControllerSourceType.Camera)
{
UIImageWriteToSavedPhotosAlbum(guardaImagen!, nil, nil, nil);
}
// arraynsuserdefault = tableImages
collectionview.reloadData()
tableControl += 1
}
//NO ESTA EN EL TUTORIAL
dismissViewControllerAnimated(true, completion: nil)
}
// metodo tambien del delegado que detecta si se presiono cancel en el picker
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
dismissViewControllerAnimated(true, completion: nil)
}
func deleteUser(sender:UIButton) {
let i : Int = (sender.layer.valueForKey("index")) as! Int
//tableData.removeAtIndex(i)
// tableData = nil
let image : UIImage = UIImage(named:"cup.png")!
tableImages[i] = image
//tableControl--
collectionview.reloadData()
}
func respondToSwipeGesture(gesture: UIGestureRecognizer) {
if let swipeGesture = gesture as? UISwipeGestureRecognizer {
}
}
@IBAction func cancelar(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
@IBAction func BorrarFotos(sender: AnyObject) {
tableImages.removeAll()
tableData.removeAll()
tableControl = 0
collectionview.reloadData()
}
}
答
有可能是一些导致此问题的问题。
您没有在您调用ALCameraViewController对象的文件顶部导入ALCameraViewController。 README.md不会告诉你这样做,但为了让你的项目能够识别它,这是必要的。
您没有Xcode 7.3和Swift 2.2。一些语法与Swift 2.1到2.2不同。所以确保你有你的操作系统,Xcode程序和Swift语言更新。
你可以直接在问题中发布你的代码和错误消息,而不是提供一个截图的链接? – NobodyNada
是的,它已经准备好 –
现在,我得到的错误: pantalla6.swift:10:8:没有这样的模块'ALCameraViewController' –