Skip to content
This repository has been archived by the owner on Oct 9, 2021. It is now read-only.

Images change places in TableView #20

Closed
dosymbaev opened this issue Jul 28, 2017 · 11 comments
Closed

Images change places in TableView #20

dosymbaev opened this issue Jul 28, 2017 · 11 comments

Comments

@dosymbaev
Copy link

When I scroll the images are set not on proper cells, then when i stop scrolling it reloads and puts back the correct image.

@BeauNouvelle
Copy link
Owner

BeauNouvelle commented Aug 3, 2017

Yeah I suppose I never considered these to be used in a tableview.
Some sort of caching on the position of the image would be a welcome feature.

I'll look into it, or feel free to come up with something yourself and pull request.

Thank you.

@BeauNouvelle
Copy link
Owner

@dosymbaev are you able to put together a quick demo app showing this?

@BeauNouvelle
Copy link
Owner

Closing due to inactivity.

@seenoevo
Copy link

seenoevo commented Jan 15, 2018

I am facing the same issue using a UICollectionView.

I am downloading images from a database and if I scroll before some images are loaded into the cell, I get occasional same images in different cells.

Can you take a look at this?

I would provide you a sample code, but my app has a lot of code and eliminating only what's useful for you would take a long time.

Thanks

@BeauNouvelle BeauNouvelle reopened this Jan 15, 2018
@BeauNouvelle
Copy link
Owner

I'll have a look. Extensions seem to be rather limited with what we can do, but I might be able to work something out.

@seenoevo
Copy link

Wow, that's the fastest reply from a developer I've ever seen.

Thanks!

Please let me know as soon as you can resolve. I would love to use this for my app!

@BeauNouvelle
Copy link
Owner

No problem :)

@algrid
Copy link
Contributor

algrid commented Feb 10, 2018

I’m able to reproduce this problem. The key point is that the face recognition is done in a background thread and when it’s done the image is set. When images are set very fast (during table view scroll) those background tasks build up and one can see successive image changes. Theoretically even the wrong image can be set in the end (can’t reproduce that).

To solve that we would need to cancel previous tasks when setting a new image. Or check at the end of background processing that the image wasn’t changed. Anyway all this requires a new property added, which is not possible in a Swift extension. In fact it’s possible through an objective c hack, but a direct approach would be to switch to inheritance instead of extension. Not sure what approach would be better.

@BeauNouvelle
Copy link
Owner

BeauNouvelle commented Feb 12, 2018 via email

@CocoaML
Copy link

CocoaML commented Oct 13, 2018

No problem :)

When I FaceAwared the ImageView , I want to cache the info to scroll TableView smoothly, such as the Image and Frame. and I write a func.

func setLocalFaceImageAndFrame(aImage: UIImage?, aFrame: CGRect?) {
    let layer = self.imageLayer()
    layer.contents = aImage!.cgImage
    layer.frame = aFrame!
}

But I can not use this func with OC code. like this :
[aImageView setLocalFaceImageAndFrame: aFrame image: aImage]

How can I deal with it ? Thanks !

Ok, I solve it with The code.

@objc
public func setLocalFaceImage(infoDic: NSDictionary) {
let aImage = infoDic["image"] as! UIImage
let aFrame = infoDic["frame"]

    let layer = self.imageLayer()
    layer.contents = aImage.cgImage
    layer.frame = aFrame as! CGRect
}

Thanks.

@AndreiApostoiu
Copy link

No problem :)

When I FaceAwared the ImageView , I want to cache the info to scroll TableView smoothly, such as the Image and Frame. and I write a func.

func setLocalFaceImageAndFrame(aImage: UIImage?, aFrame: CGRect?) {
    let layer = self.imageLayer()
    layer.contents = aImage!.cgImage
    layer.frame = aFrame!
}

But I can not use this func with OC code. like this :
[aImageView setLocalFaceImageAndFrame: aFrame image: aImage]
How can I deal with it ? Thanks !

Ok, I solve it with The code.

@objc
public func setLocalFaceImage(infoDic: NSDictionary) {
let aImage = infoDic["image"] as! UIImage
let aFrame = infoDic["frame"]

    let layer = self.imageLayer()
    layer.contents = aImage.cgImage
    layer.frame = aFrame as! CGRect
}

Thanks.

Where and how do you use this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants