0
我正在使用集合視圖在解析中加載我的圖像和標籤。我正在使用下面的代碼。減少解析集合視圖中的加載時間
func loadCollectionViewData() {
// Build a parse query object
var query = PFQuery(className:"Posts")
query.whereKey("uploader", equalTo: PFUser.currentUser()!)
// Check to see if there is a search term
if searchTextF != "" {
query.whereKey("imageText", containsString: searchTextF.text)
//query.whereKey("Tags", containsString: searchTextF.text)
}
// Fetch data from the parse platform
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
println("objects: \(objects)")
println("error\(error)")
// The find succeeded now rocess the found objects into the countries array
if error == nil {
// Clear existing country data
tops.removeAll(keepCapacity: false)
// Add country objects to our array
if let objects = objects as? [PFObject] {
tops = Array(objects.generate())
}
// reload our data into the collection view
self.collectionView.reloadData()
self.hideActivityIndicator(self.view)
} else {
// Log details of the failure
println("Error: \(error!) \(error!.userInfo!)")
if self.checkAlert == 0{
let alert = SCLAlertView()
alert.showError("Error", subTitle:"An error occured while retrieving your clothes. Please check the Internet connection.", closeButtonTitle:"Ok")
self.hideActivityIndicator(self.view)
self.checkAlert = 1
}
}
}
}
但是,使用此代碼,它會從解析中檢索所有圖像,並且需要時間加載。我想減少加載時間。我該如何做到這一點,以便它一次加載10個,並且當用戶拉下另一個10時加載?我整天都在搜索,無法在swift中找到關於此主題的任何資源。謝謝
如果你有多個圖像,那麼你必須檢查https://github.com/rs/SDWebImage –
謝謝。是的,我正在看它,但可以快速使用它嗎?但我認爲,即使我使用它,它仍然會一次加載圖像。 – KSatsuki
你必須緩存圖像 –