Swift3 为什么我的收藏视图没有';你不给我看胶卷吗?

Swift3 为什么我的收藏视图没有';你不给我看胶卷吗?,swift3,collectionview,camera-roll,Swift3,Collectionview,Camera Roll,我有一个收集视图,应该显示相机卷照片,但它没有显示任何东西! 我看到了类似的问题,但他们的代码不起作用! 我在Info.plist中添加了使用相册照片的隐私 这是我的密码 class ViewController: UICollectionViewController , UICollectionViewDelegateFlowLayout { override func viewDidLoad() { grabPhotos() } func grabPhotos() {

我有一个收集视图,应该显示相机卷照片,但它没有显示任何东西! 我看到了类似的问题,但他们的代码不起作用! 我在Info.plist中添加了使用相册照片的隐私 这是我的密码

class ViewController: UICollectionViewController , UICollectionViewDelegateFlowLayout {



override func viewDidLoad() {
    grabPhotos()
}
func grabPhotos() {

    var imageArray = [UIImage]()

    let imgManager = PHImageManager.default()

    let requestOptions = PHImageRequestOptions()

    requestOptions.isSynchronous = true

    requestOptions.deliveryMode = .highQualityFormat

    let fetchOptions = PHFetchOptions()

    fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]

      if let fetchResult: PHFetchResult = PHAsset.fetchAssets(with: PHAssetMediaType.image, options: fetchOptions) {



        if fetchResult.count > 0 {


            for i in 0..<fetchResult.count {

                imgManager.requestImage(for: fetchResult.object(at: i) , targetSize: CGSize(width: 200, height: 200), contentMode: .aspectFill, options: requestOptions, resultHandler: {


                    image , error in



                    imageArray.append(image!)

                })




            }







        }
        else {

            print("No Photos")
            self.collectionView?.reloadData()

        }



    }


    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return imageArray.count


    }

        func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath as IndexPath)


            let imageView = cell.viewWithTag(1) as! UIImageView


             imageView.image = imageArray[indexPath.row]


             return cell


    }

}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout:
    UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {

    let width = collectionView.frame.width / 3 - 1




    return CGSize(width: width, height: width)


}


func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
    return 1.0
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
    return 1.0 
}
}
类ViewController:UICollectionViewController,UICollectionViewDelegateFlowLayout{
重写func viewDidLoad(){
抓取照片()
}
func grabPhotos(){
var imageArray=[UIImage]()
让imgManager=PHImageManager.default()
让requestOptions=PHImageRequestOptions()
requestOptions.isSynchronous=true
requestOptions.deliveryMode=.highQualityFormat
让fetchOptions=PHFetchOptions()
fetchOptions.sortDescriptors=[NSSortDescriptor(键:“creationDate”,升序:true)]
如果let fetchResult:PHFetchResult=PHAsset.fetchAssets(带:PHAssetMediaType.image,选项:fetchOptions){
如果fetchResult.count>0{
对于0..Int中的i{
返回imageArray.count
}
func collectionView(collectionView:UICollectionView,cellForItemAtIndexPath indexPath:NSIndexPath)->UICollectionViewCell{
let cell=collectionView.dequeueReusableCell(withReuseIdentifier:“cell”,for:indepath作为indepath)
让imageView=cell.viewWithTag(1)为!UIImageView
imageView.image=imageArray[indexPath.row]
返回单元
}
}
func collectionView(collectionView:UICollectionView,布局collectionView布局:
UICollectionViewLayout,参考SizeForHeaderInstruction部分:Int)->CGSize{
let width=collectionView.frame.width/3-1
返回CGSize(宽度:宽度,高度:宽度)
}
func collectionView(collectionView:UICollectionView,布局collectionViewLayout:UICollectionViewLayout,MinimumLineSpacingforSection:Int)->CGFloat{
返回1.0
}
func collectionView(collectionView:UICollectionView,布局collectionViewLayout:UICollectionViewLayout,MinimumItemSpacingForSection:Int)->CGFloat{
返回1.0
}
}

它没有显示任何内容我读过类似的问题,但它们对我没有帮助

您在获取图像后是否尝试重新加载collectionview?顺便说一句,在
grabPhotos()之前调用
super.viewDidLoad()
很好。您在获取图像后是否尝试重新加载collectionview?顺便说一句,调用
super.viewDidLoad()很好
抓取照片()之前