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

iOS 10. Dragging cell disappears #16

Closed
mrikh opened this issue Apr 12, 2018 · 8 comments
Closed

iOS 10. Dragging cell disappears #16

mrikh opened this issue Apr 12, 2018 · 8 comments

Comments

@mrikh
Copy link

mrikh commented Apr 12, 2018

Whenever i try to drag a cell by pressing on the top edge of the cell. The cell vanishes and isn't visible in the debug view heirarchy either. Here is what happens:

The delegate method for willBeginDragging gets called but didEndDraggingAt isn't called and in this particular case ONLY, the following gets printed into the logs:

"Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates."

Here is a screenshot:

screen shot 2018-04-12 at 3 08 36 pm

@KyoheiG3
Copy link
Owner

Hi @mrikh
I tried to fix the issue on this branch.
Could you try it?

@mrikh
Copy link
Author

mrikh commented Apr 14, 2018

Hi @KyoheiG3,
I already tried setting after screen updates to true but that doesn't seem to solve the problem :)

@KyoheiG3
Copy link
Owner

I do not know what is happening. Can you tell me the code that does not work?

@mrikh
Copy link
Author

mrikh commented Apr 16, 2018

Basically what happens is, the draggingCell is returned nil from inside this method:

func copiedCell(at indexPath: IndexPath) -> UIView? {
        return dataSource?.dragger?(self, cellForRowAt: indexPath) ?? targetTableView?.cellForRow(at: indexPath)?.snapshotView(afterScreenUpdates: false)
    }

I tried implementing the datasource and return the cell but that still doesn't solve the problem.

I cannot provide you a sample directly from the code i am using due to well it being an official organisation project and i'll be able to provide a sample after i get the time.

This happens only when i click the boundary of the cell and try to drag, never when i long press inside the cell itself

@KyoheiG3
Copy link
Owner

Thanks for your information. I will try it.

@mrikh
Copy link
Author

mrikh commented Apr 16, 2018

So i managed to do a hackish fix to the problem, i changed the method to this:

func copiedCell(at indexPath: IndexPath) -> UIView? {
        
        if let view = dataSource?.dragger?(self, cellForRowAt: indexPath){
            return view
        }else if let cell = targetTableView?.cellForRow(at: indexPath){
            if let view = cell.snapshotView(afterScreenUpdates: false){
                return view
            }else{
                
                let data = NSKeyedArchiver.archivedData(withRootObject: cell)
                if let tempCell = NSKeyedUnarchiver.unarchiveObject(with: data) as? UITableViewCell{
                    tempCell.frame = cell.bounds
                    return tempCell
                }else{
                    return nil
                }
            }
        }
        
        return nil
    }

And the problem seems to be resolved

@KyoheiG3
Copy link
Owner

Awesome! I did not get any problem, but I want to take your code into the method.

@KyoheiG3
Copy link
Owner

Fixed in #17. Please check it out.

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

No branches or pull requests

2 participants