减少解析集合视图中的加载时间

时间:2015-08-08 03:44:27

标签: ios swift parse-platform uicollectionview lazy-loading

我正在使用集合视图在解析中加载我的图像和标签。我正在使用下面的代码。

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中找到有关此主题的任何资源。谢谢

1 个答案:

答案 0 :(得分:0)

您应该使用PFImageView而不是UIImageView并使用其loadInBackground()方法加载PFFile。