Uicollectionview Reloaddata Not Functioning Properly in iOS 7

reloadData not working for UICollectionView in iOS7

  • After writing reloadItemsAtIndexPaths no need of writing again
    reloadData.
  • Reload the respective collection View row using main thread.

Code Snippet:

[[NSOperationQueue  mainQueue]  addOperationWithBlock:^{

// Reload the respective collection view row using the main thread.

[self.collectionView reloadItemsAtIndexPaths:[self.collectionView indexPathsForVisibleItems]];

}];

UICollectionView Reload Data Not Working to update CollectionView

You can't update UI elements in a background thread. [self.collectionView reloadData] is called from parseRss which is itself called form parseFeed which is called by an operation on _queue. if _queue doesn't happen to be processed by the main thread, you will get unpredictable results in the collectionView and more likely crashes.

You should dispatch your call to [self.collectionView reloadData] to the main thread.

dispatch_async(dispatch_get_main_queue(), { self.collectionView.reloadData() })

(this is the Swift syntax, i'm not familiar with Obj-C, sorry)

UICollectionView does not reloadData

If you get the error on this line...

self.collectionView.reloadData()

.. then either self or collectionView could be nil. To check this just place a breakpoint on this line and check which is nil - either self or collectionView. If you do not know how to set breakpoints and check values in the debugger then please search for tutorials - it's easy, but to much to explain here. You will have to learn this anyway if you want to continue programming.

And: removing the "weak" from the collectionView is a bad idea because it could lead to a reference cycle and a memory leak.

UICollectionView won't reloadData() after UIImagePickerController dismisses

Your lookUpPhotos function is fine, but you can update the collectionView at the end of your query.

func lookUpPhotos() {

let findPhotos = PFQuery(className: "Gallery")
findPhotos.whereKey("dogID", equalTo: self.dogObjectID)
findPhotos.orderByDescending("createdAt")
findPhotos.findObjectsInBackgroundWithBlock {
(objects, error) -> Void in

if let users = objects {
for object in users {
self.photoData.addObject(object)
print("Fetched \(self.dogSelectedName)'s \(self.photoData.count) Images")
}
}

dispatch_async(dispatch_get_main_queue()) { () -> Void in
self.collectionView.reloadData()
}
}
}

You can then call the lookUpPhotos function again once you send the data.

saveImage.saveInBackgroundWithBlock { (Bool, error) -> Void in
if error != nil {
print("There was an error")
} else {
print("New Gallery object saved: \(saveImage)")
dispatch_async(dispatch_get_main_queue()) { () -> Void in
self.dismissViewControllerAnimated(true) { () -> Void in
self.lookUpPhotos()
}
}
}
}

UICollectionView stuck in reloadData

Never do UIKit stuff from a background thread. So make sure reloadData is called on the main thread and don't modify the backing array from a background thread.

UICollectionView reloadData seems slow/laggy (not instantaneous)

Some possibilities:

  • Your presumably recursive function to set the fonts is probably expensive.
  • A few of the other Universal functions look like they might be expensive.
  • It does not appear that you ever remove the button target and every time a cell is reused, you are adding additional targets to it.
  • imageWithContentsOfFile: skips the cache; use imageNamed: instead.


Related Topics



Leave a reply



Submit