У меня есть запрос Parse.com около 150 изображений, заполняющих UICollectionView. Изображения изменяются в соответствии с кнопкой, которую пользователь набирает, чтобы перейти в UICollectionView. При прослушивании коллекция начинает загружаться, и вы можете увидеть первые три или четыре изображения довольно скоро.Как оптимизировать UICollectionView, заполняемый с помощью запроса Parse.com?
При прокрутке, однако, вы видите те же изображения, которые уже были скопированы и перетасованы, переключая места с изображениями, которые еще не загружены. В конечном итоге все они загружаются, но это занимает много времени. (Как и 90 секунд.) И, кроме того, изображения не загружаются, пока пользователь не прокрутит изображение до места изображения и не ждал его.
Я начинающий разработчик, поэтому я не знаю, является ли это очевидным исправлением или чем-то, что требует серьезной работы. Мой код здесь:
код UICollectionView:
var exp = ""
class CollectionCollectionViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
images = []
parseObjects = []
imageNames = []
imageExpansions = []
var downloadCards = PFQuery(className: "Cards")
downloadCards.whereKey("ExpansionNumber", equalTo:"\(exp)")
downloadCards.limit = 200
downloadCards.orderByAscending("Number")
downloadCards.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
println("Successfully retrieved \(objects!.count) cards.")
if let objects = objects as? [PFObject] {
for object in objects {
parseObjects.append(object["Image"] as! PFFile)
imageNames.append(object["Number"] as! String)
imageExpansions.append(object["ExpansionNumber"] as! String)
self.collectionView.reloadData()
}
}
} else {
println("Error: \(error!) \(error!.userInfo!)")
}
}
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return parseObjects.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: CardsCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CardsCollectionViewCell
parseObjects[indexPath.row].getDataInBackgroundWithBlock{
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
let image = UIImage(data: imageData!)
cell.cardsImg.image = image
}
}
//cell.cardLabel.text = imageNames[indexPath.row]
return cell
}
}
Кнопка Segue/запрос идентификационный код здесь:
var images = [UIImage]()
var parseObjects = [PFFile]()
var imageNames = [String]()
var imageExpansions = [String]()
class selectExpansionViewController: UIViewController {
@IBAction func xy1Button(sender: AnyObject) {
exp = "59"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func xy2Button(sender: AnyObject) {
exp = "60"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func xy3Button(sender: AnyObject) {
exp = "61"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func xy4Button(sender: AnyObject) {
exp = "62"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func xy5Button(sender: AnyObject) {
exp = "63"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func xydcButton(sender: AnyObject) {
exp = "63-2"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func xy6Button(sender: AnyObject) {
exp = "64"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func bw1Button(sender: AnyObject) {
exp = "48"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func bw2Button(sender: AnyObject) {
exp = "49"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func bw3Button(sender: AnyObject) {
exp = "50"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func bw4Button(sender: AnyObject) {
exp = "51"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func bw5Button(sender: AnyObject) {
exp = "52"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func bw6Button(sender: AnyObject) {
exp = "53"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func bw7Button(sender: AnyObject) {
exp = "54"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func bw8Button(sender: AnyObject) {
exp = "55"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func bw9Button(sender: AnyObject) {
exp = "56"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func bw10Button(sender: AnyObject) {
exp = "57"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func bw11Button(sender: AnyObject) {
exp = "58"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func hgss1Button(sender: AnyObject) {
exp = "43"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func hgss2Button(sender: AnyObject) {
exp = "44"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
@IBAction func hgss3Button(sender: AnyObject) {
exp = "45"
self.performSegueWithIdentifier("jumpToCollectionView", sender: self)
}
Спасибо за совет, но это не то, о чем я просил. –