nicolasgomollon / lprtableview Goto Github PK
View Code? Open in Web Editor NEWA drop-in replacement for UITableView and UITableViewController that supports long-press reordering of cells.
License: MIT License
A drop-in replacement for UITableView and UITableViewController that supports long-press reordering of cells.
License: MIT License
I have several sections in a table view and only want one of the sections to be draggable. Is this possible?
Would it have swift 2.0 support?
The definition of longPressReorderDelegate
creates a strong reference cycle when used, which means the class you assign to it is never deinit()
which creates a memory leak.
This is because the delegate is declared as:
open var longPressReorderDelegate: LPRTableViewDelegate!
When it should be:
weak open var longPressReorderDelegate: LPRTableViewDelegate?
Notice I also removed the forced unwrap as delegates should always be optionally unwrapped. Which is done everywhere in the code, so it's surprising it was declared as such.
Downloaded the sample ReorderTest and changed the style to "Subtitle"
Added cell.detailTextLabel?.text = object.description to cellForRowAtIndexPath
This stil gives me the same basic tableviewcell.
I' m using Xcode 6.4. It compiles shows 2 error on the following code:
public convenience override init() {
self.init(frame: CGRectZero)
}
removing the override
fixed the error of LPRTableView.swift:55:30: Initializer does not override a designated initializer from its superclass
.
public var lprTableView: LPRTableView! { return tableView as LPRTableView }
changing as
to as!
fixed the error of LPRTableView.swift:304:60: 'UITableView!' is not convertible to 'LPRTableView'; did you mean to use 'as!' to force downcast?
Hello, I'll use this opportunity to say thank you for sharing this with us.
I ran into an issue that I'm trying to solve with your approach at dragging cells.
I suspect the problem is somewhere around the
//reload the rows that were affected just to be safe
or at the moveRowAtIndexPath function.
When you drag the cell slow and gentle everything works perfectly but when you drag the cell fast and kind of drop it as if you wouldn't care where it will land or you move it around the table quick without releasing and then drop it quick what will happen is that more than one cell will chage it's text as if more than one cell's content has moved it's row. It just looks like if you release the cell before it falls into the new row it will call the moveRowAtIndexPath more than once.
Say we have 7 rows that display 1 to 7 in ascending order and we drag a cell and move it quick and drop and let's say it landed at 2, instead of only the cell 7 and 2 to switch positions another random cell pair along the path(in this case 4 and 5) will change the position and the result will look like.
1
7
3
5
4
6
2
The more rows you have the more likely this will happen.
I hope I was clear enough. Let me know if you need a video to demonstrate this.
Thank you!
Noticed this in the latest build. iOS 10.3.1
If you click and drag one view, then rapidly move it up and down between some views, one view will stop moving and stay either higher or lower than it should. After dropping the selected cell when this occurs, the cell which was misplaced earlier will sometimes teleport to another location.
Thank you for the great library. Saved me a lot of stress, and the code is very top quality. :)
EDIT: Noted that an issue was closed for it here, although the bug does still seem to persist: #5
This is really nice, thank you! :)
I know that the moveRowAt
method fires when you reorder the cells, but it fires each time the row moves, even if the user hasn't let go yet.
Is there a method that fires when a user lets go of the cell and commits the reorder change? That's when I'd like to save the data to my database.
If the prototype cell is a custom class, it crashes.
I create my custom cell
< class MyCellClass: UITableViewCell {>
< // code>
< }>
I associate it with the prototype cell in the storyboard.
And it crashes on this line :
< let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! MyCellClass>
=> Could not cast value of type 'UITableViewCell' (0x10bf7ec68) to 'ReorderTest. MyCellClass'
Is there a way to avoid that ?
Hello, i implemented an expand collapse logic on the section with your framework working behind for the autoscroll and the drag and drop.
Though i encountered a problem, i cannot drop the cell in a collapse section, it works sometimes but never for the first section which is at the top of the screen.
Any idea on where i should focus to change that?
Hello,
There is a problem when the user cancels the drag&drop, e.g. by leaving the app. When the user then resumes their activity, the cell still looks like it's being dragged although there is no drag&drop action going on (anymore).
To reproduce:
I guess we should cancel the drag&drop (either accepting or rejecting the current position) somewhere around here:
if gesture.state == .cancelled
Can you fix this issue?:-)
Is it possible to implement this framework for re-ordering sections by getting indexPath from a selected point. I can manage to do it on my own without this framework but I am having difficulties with the scrolling so I was wondering if I could use this instead.
Even with this framework I have got it working to move the sections but I cannot implement the scrolling again.
Hi there, absolutely love the library.
I recently discovered an issue in testing that is easily reproducible. I'm going to try and fix it myself though I figured I'd share it here too in case anyone else already has a solution.
Issue
When the cell height is greater than the standard height (which I believe is 44), and you move a cell near the bottom of the table view, the cells jump around the screen in an odd manner. Please note you have to have more cells than can fit on the screen to reproduce this.
Video demonstration
https://www.youtube.com/watch?v=MlTH87Wj7so
Steps to reproduce
I believe this issue may only occur on iOS 11. I cannot reproduce it on an iPad running iOS 9.3.5 or an iPhone 6 running iOS 10.3.3, so ensure you're running iOS 11.
Override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
and return a value of 100 (my testing value).
Ensure there are at least 2 "full screens" worth of rows.
Go to the bottom of the table view, begin to drag & drop any cell near the bottom. Move it upwards or downwards and notice the odd behaviour.
Thanks for reading!
Edwin
Following your example I set my ViewController for my TableViewController View to inherit LPRTableViewController and I am getting "unable to dequeue cell" errors.
The cells exist, they are Custom Prototypes in the TableViewController, no custom classes. If I modify
func registerClasses() {
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "newIdentifier")
}
Then I have to unwrap all the labels and no values are displayed.
If I leave my TableViewController inheritance as UITableViewController and set the table view of the TableViewController to LPRTableView it does work, but hideDraggingView is never triggered.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.