2017-12-06 18 views
0

질문배열에 사진을 추가 및 UICollection보기 오류로 표시

이 코드는 배열에 이미지를 설정 작동하지만 다음과 같은 오류와 함께 제공 - 2017년 12월 6일 12 : 31 : 21.264812 0000 SmartReceipts [880 : 172369] 확장을 발견하면서 [발견] 오류가 발생했습니다 오류 도메인 = PlugInKit 코드 = 13 "쿼리가 취소"사용자 정보 = {NSLocalizedDescription = 쿼리가 취소}

나는 이것이 무엇을 의미하는지 알 필요가

및 주변에 가능한 수정이 있다면?

import UIKit 

class GalleryController: UICollectionViewController, 
         UIImagePickerControllerDelegate, 
         UINavigationControllerDelegate { 

    var Receipts = [UIImage?]() 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     self.collectionView?.reloadData() 





     // Uncomment the following line to preserve selection between presentations 
     // self.clearsSelectionOnViewWillAppear = false 

     // Register cell classes 
     //self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) 


    } 

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

     self.dismiss(animated: true, completion: nil) 
     print(info); 
     let newReceipts = info[UIImagePickerControllerEditedImage] as? UIImage 
     self.Receipts.append(newReceipts) 

     print("Array Contains \(self.Receipts.count) Receipts") 
     print(self.Receipts) 
     self.collectionView?.reloadData() 

     print("completedIfStatement") 
     } 







    @IBAction func getReceipts(_ sender: Any) { 
     print("PlusButtonPressed") 

     let optionMenu = UIAlertController(title: nil, message: "Choose Option", preferredStyle: .actionSheet) 

     // 2 
     let albumAction = UIAlertAction(title: "Album", style: .default, handler: { 
      (alert: UIAlertAction!) -> Void in 
      print("PhotosOption") 
      self.getFromReceipts() 
     }) 
     let cameraAction = UIAlertAction(title: "Camera", style: .default, handler: { 
      (alert: UIAlertAction!) -> Void in 
      print("CameraOption") 
      self.getFromCamera() 
     }) 

     // 
     let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: { 
      (alert: UIAlertAction!) -> Void in 
      print("Cancel") 
     }) 


     // 4 
     optionMenu.addAction(albumAction) 
     optionMenu.addAction(cameraAction) 
     optionMenu.addAction(cancelAction) 

     // 5 
     self.present(optionMenu, animated: true, completion: nil) 

    } 


    func getFromReceipts() { 

     print("GetFromReceipts") 
     let cameraPicker = UIImagePickerController() 
     cameraPicker.delegate = self 
     cameraPicker.sourceType = .photoLibrary 

     self.present(cameraPicker, animated: true, completion: nil) 


    } 

    func getFromCamera() { 
     print("GetFromCamera") 
     let cameraPicker = UIImagePickerController() 
     cameraPicker.delegate = self 
     cameraPicker.sourceType = .camera 

     self.present(cameraPicker, animated: true, completion: nil) 

    } 



    //Number of Views 
    override func numberOfSections(in collectionView: UICollectionView) -> Int { 
     return 1 
    } 

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
     return self.Receipts.count 
    } 

    func collectionView(collectionView: UICollectionView, cellForItemAtindexPath indexPath: NSIndexPath) -> UICollectionViewCell { 

     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: Receipts, for: indexPath as IndexPath) as? PhotoCell 


     cell?.imageView.image = self.Receipts[indexPath.row] 
     return cell! 

    } 

} 
+0

되는 오류가 발생 라인 :

<key>NSPhotoLibraryUsageDescription</key> <string>${PRODUCT_NAME} Photo Usage</string> 

그리고 you'r 소스 코드

는,이 코드 (스위프트 3)를 추가 할 필요가있는 사진/카메라에 대한 권한을 물어? 중단 점을 설정하고 확인하십시오. – Retterdesdialogs

답변

0

내가 you'r이 사진/카메라 권한을 요청하지 같아요. Info.plist에 아래의 키를 추가해야합니다.

카메라 권한 :

<key>NSCameraUsageDescription</key> 
<string> ${PRODUCT_NAME} Camera Usage< </string> 

사진 라이브러리를 들어, 당신이 하나의 앱 사용자가 사진 라이브러리를 검색 할 수 있도록 할 것입니다.

PHPhotoLibrary.requestAuthorization({ 
     (newStatus) in 
     if newStatus == PHAuthorizationStatus.authorized { 
      /* do stuff here */ 
    } 
}) 
+0

완성되었지만 여전히 오류가 발생했습니다. 권한을 묻습니다. 이미지를 클릭하면 오류가 계속 발생합니다. ?? –

+0

'func imagePickerController (_ picker : UIImagePickerController, didFinishPickingMediaWithInfo info : [String : Any])'의 끝에 포토 피커를 닫아야합니다. –