Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reordering dynamically sized cells causes content to jump around significantly #6

Open
adamshin opened this issue Sep 14, 2016 · 7 comments · May be fixed by #67
Open

Reordering dynamically sized cells causes content to jump around significantly #6

adamshin opened this issue Sep 14, 2016 · 7 comments · May be fixed by #67
Assignees

Comments

@adamshin
Copy link
Owner

This occurs when the content size is larger than the table view bounds. Probably an issue with cell height calculations.

@adamshin adamshin self-assigned this Sep 14, 2016
@ay8s
Copy link

ay8s commented Sep 14, 2016

Great one @adamshin. I think the issue is the cells move the movement of the cells then trigger another move which causes a loop. I believe similar logic to whats here might fix this up although I could be wrong. https://github.com/Raizlabs/LXReorderableCollectionViewFlowLayout/blob/master/LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m#L157

@adamshin
Copy link
Owner Author

Thanks for the tip, I'll take a look at that.

@adamshin
Copy link
Owner Author

@ay8s Spent some time debugging this today -- unfortunately, it appears to be a UIKit issue. 😞 Calling insertRows(at:with:) or deleteRows(at:with:) on a table view with dynamically-sized cells causes the content offset to shift around unpredictably. Seems like it's related to the estimated row height you give.

I wasn't able to come up with a satisfactory solution, so I'm going to table this for now. In the meantime, a workaround would be to calculate cell heights manually (the pre-iOS 8 way).

@lkuraer
Copy link

lkuraer commented Jan 16, 2018

just do this in viewcontroller to fix this jumping:

  1. var cellHeights = NSMutableDictionary()

  2. func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
     if let height = cellHeights.object(forKey: indexPath) {
         return height as! CGFloat
     }
    
     return UITableViewAutomaticDimension
    

    }

  3. func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
     cellHeights.setObject(cell.frame.size.height, forKey: indexPath as NSCopying)
    

    }

This fixed the issue on my side.

@cliftonlabrum
Copy link

Is there a way to implement these changes within the source itself so I don't have to add all this to each of my tableViews?

@anton-plebanovich
Copy link
Contributor

I'm using extension for UITableView - https://github.com/APUtils/APExtensions/blob/master/APExtensions/Classes/Core/_Extensions/UITableView%2BUtils.swift#L82

Then it's just one line of code: tableView.handleEstimatedSizeAutomatically = true

@anton-plebanovich
Copy link
Contributor

Fixed in #67

@anton-plebanovich anton-plebanovich linked a pull request Jan 18, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants