2016-08-13 63 views
0

我有一個從庫加載的collectionview.Currently所有圖像列出。但最古老的圖像列出first.I希望顯示它們從最新顯示第一到最古老。如何做這個??如何將圖像從最新到最舊顯示到collectionviewe

下面的代碼是什麼我currenly using.How更新此序從開始最新列表,圖像,歷史最悠久的

if PHPhotoLibrary.authorizationStatus() == PHAuthorizationStatus.Authorized 
    { 
     let collection:PHFetchResult = PHAssetCollection.fetchAssetCollectionsWithType(.SmartAlbum, subtype: .SmartAlbumUserLibrary, options: nil) 

     var i = 0 
     repeat 
     { 
      if (collection.count > 0) 
      { 
       if let first_Obj:AnyObject = collection.objectAtIndex(i) 
       { 
        self.assetCollection = first_Obj as! PHAssetCollection 
       } 
       i += 1 
      } 
     }while(i < collection.count) 
    } 

回答

1

您可以使用PHFetchOptions

PHFetchOptions Class Reference>sortDescriptors

試試這個:

 let options = PHFetchOptions() 
     options.sortDescriptors = [NSSortDescriptor(key: "endDate", ascending: false)] 
     let collection:PHFetchResult = PHAssetCollection.fetchAssetCollectionsWithType(.SmartAlbum, subtype: .SmartAlbumUserLibrary, options: options) 
相關問題