2015-11-02 202 views
0

我使用的是照片的框架使用此代碼在iOS8上獲取專輯列表,
如何重新排序smartAlbums,這樣我就可以顯示在所有如何重新排序PHAssetCollection列表

let smartAlbums : PHFetchResult = PHAssetCollection.fetchAssetCollectionsWithType(PHAssetCollectionType.SmartAlbum, subtype: PHAssetCollectionSubtype.AlbumRegular, options: nil) 

頂「最近添加」在cellForRow方法

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

      let collection = smartAlbums[indexPath.row] 
      cell.textLabel?.text = collection.localizedTitle 
      return cell 

    } 

enter image description here

let photofetchOpt:PHFetchOptions? = PHFetchOptions() 
    photofetchOpt?.sortDescriptors = [NSSortDescriptor(key:"localizedTitle", ascending: false)] 

我試圖在獲取AssetCollections時使用PHFetchOptions,但對smartAlbums的順序沒有影響。

回答

1

我得到了重新排序PHCollectionList的解決方案,我張貼這個答案的人誰正在努力重新排序清單 基本上我使用NSMutableAllray「sortedSmartAlbumsCollectionsFetchResults」

if(smartAlbums.count > 0) 
     { 
      for i in 0...smartAlbums.count-1 
      { 
       let assetCollection:PHAssetCollection = smartAlbums[i] as! PHAssetCollection 

       if assetCollection.assetCollectionSubtype == PHAssetCollectionSubtype.SmartAlbumRecentlyAdded 
       { 
        sortedSmartAlbumsCollectionsFetchResults.insertObject(assetCollection, atIndex: 0) 
       } 
       else 
       { 
        sortedSmartAlbumsCollectionsFetchResults.addObject(assetCollection) 
       } 
      } 
     } 

,如上面的代碼中,我有提取每個從smartAlbums PHAssetCollection並檢查它是否是YES時,在別的0指數插入繼續添加在nsmutableAllray

看到導致亞型SmartAlbumRecentlyAdded

enter image description here