In my ios project I'm using a uicollectionview and custom CollectionViewCells to load local images saved on the device (through ALAssets).
My problem occurs when the user scrolls down and then back up. It seems as though it takes long enough for ALAssets to load the image (I'm not using the thumbnail version) which gets it confused and sets the cell's wrong image. I know for sure that it's the wrong cell's image, as it has already been set in the past with the correct image.
How can I overcome this issue and synchronize the image loaded?
Cancel ALAssets operations connected to each cell inside this function:
- (void)prepareForReuse
in your custom cells class. That should prevent updating image on cell which were reused and which has different content.
Related
First of all, I do not want to create a simple 2 or 3 columns gallery. I need exactly like the screenshot of Photos App, I've attached to the question. Big image can be paginated, thumbnails ill be scrolled, selected image's thumbnail will be animated.
I have some ideas.
1st, I can use collection view for the thumbnail scroller. (I have already done that.) But big images' pagination and animation of the selected images thumbnail is the trick here.
2ns, I can use UIPageViewController for the big image, but how can I achieve the page control with the thumbs, it is the problem.
Any ideas? Thank you.
You can do that observing the scroll view of the thumbnail's UICollectionView. UICollectionViewDelegate inherits from UIScrollViewDelegate, so you can receive notification of the scroll movements.
For every scroll position, check which cell is in the center point of the collection. As soon as that cell changes, you control the UIPageViewController.
I'm using a framework to asynchronously load images (Pinterest's PINRemoteImage) in combination with a UITableView. On one of my UITableViewCells I have such an image and I first initialize it with a placeholder and it's then later replaced with the real image. I don't know the real image's dimensions at time of loading and therefore the placeholder's dimensions and the ones of the real image may be different.
Using KVO, I watch the UIImageView's image property and when it's re-set to the real image, I adjust the the view's height constraint to the appropriate size. This directly shows when I first see the image. It has the appropriate size.
The cell's contentView however, does not update it's height to fit around the image (and the other views) properly until the cell get's dequeued a second time. Only then is has the cell the appropriate height.
I assume that I have to tell the table or the cell itself that it needs to update the layout manually. But between all the layout… functions I'm not quite sure which to use where right now.
So, where's the best way to make the cell update it's height to the updated image height? Other answers to similar questions on SO suggest to reload the cell, but that seems a bit too much to me. And I'd have to build a callback from the cell (where the image lives) to the table itself which could then trigger the reload.
Thanks!
I have added a table view, and I am display image in the cells. I have also added this code:
So that the cells resize depending on the image.
When I launch my app though, I get this :
[![enter image description here][1]]
And the images do not load untill I start scrolling...If I scroll down half the page then go back to the top, I get this: Which is correct
[![enter image description here][2]][2]
Any ideas? I have researched on google and tried the odd solution for the older versions of Xcode, But nothing seems to work!
If the image is already downloaded and resident in your cache when you pass the post to the cell them the image view will have an image and therefore an intrinsic content size. This all allows the table view to calculate the required layout.
If the image needs to be downloaded then the image view won't have an image and will size to zero because there is no intrinsic content size other than that.
If your images are all the same size then you can supply a placeholder image while waiting for the download and the cell will size appropriately.
Note also that you aren't updating the cell when the image has downloaded. When you do this you do need to check that the cell hasn't been reused (or you'll be showing the wrong image). If you don't have a placeholder or can't guarantee the image size then you will also need to ask the table view to update.
Maybe your post.downloadImage() and post.fetchLikes() should callback, and in callback, should reload cell in mainThread. hope it help.
I'm trying to address a slow scrolling and slow loading UIViewController that uses a UITableView with custom background cells.
When I don't set the backgroundView of the cell with an image, the performance is great. So I'm wondering if it's more performant to supply the backgroundView with images that are the actual size of my tableview row or is it better to use smaller images that are resized to fit the row's dimensions?
The images are all local and already included in the app - there's no remote fetching involved.
Improving load time of UITableView that has cells with custom background images
Try to look to use an NSOperationQueue to handle lazy loading of images and a custom tableviewcell.
Google for tweetie custom tableviewcell That should set you in the right direction.
Apple has a sample project for downloading images in tableViews: LazyTableImages
I've developing an iPad app.And I have a uitableview, in which every cell has about four to five images.And almost four to five cells on screen.
So there are about 20~30 images on screen.
The images are not very large , perhaps 200*200.(already some kind of thunbnail)
All the images are local resource.
The problem is that when first scroll down the tableview, it needs to load new cells and of course the images in the cells. This makes the UI become laggy.
But when you scroll back up ,it's very smooth. I know this is because UIImage class will cache some images.when scroll back up, the images are cached, so it's smooth.
So my question is how to deal with this?
1.Make as small thumbnail as possible?
2.Pre-load some image?(How?)
3.Use custom cache?(also how?)
I would recommend fetching the images with GCD. I would also subclass the UITableViewCell and in it's drawRect: draw all pictures on the view's layer. That will increase your performance dramatically.
If there is not so much images in the table - you can precache by loading them, when the view is created. Otherwise use more generic approach with async loading in background thread.