GithubHelp home page GithubHelp logo

reorderingtableviewcontroller's Introduction

ATSDragToReorderTableViewController
Daniel Shusta
Acacia Tree Software
<my first name> @ acaciatreesoftware.com


ATSDragToReorderTableViewController is a UITableViewController subclass that adds drag and drop reordering to a UITableView. 

I developed it as part of Acacia Tree Software’s SousChef for iPhone and it has since become an integral part of Ita for sister company Nice Mohawk. This is definitely a eating-our-own-dogfood piece of code.

A UITableView with this functionality can be reordered without switching into edit mode. It’s simply a press and hold to start, then drag the cell to reorder. The UITableView automatically scrolls when approaching the top or bottom of the UITableView.

=====

It is straightforward to incorporate into your app. 

	1.  Instead of subclassing from UITableViewController, you subclass from ATSDragToReorderTableViewController. 

	2.  Then implement the UITableViewDataSource method -tableView:moveRowAtIndexPath:toIndexPath: . You might have already done this.

	3.	If you want to better support iOS <redacted>, you'll want to check out -cellIdenticalToCellAtIndexPath:forDragTableViewController: I am very annoyed about this.

The included sample app includes these changes as a demonstration. Further details are described at the top of the ATSDragToReorderTableViewController.h .

For those curious, ATSDragToReorderTableViewController.m includes a fairly comprehensive overview of the implementation at the top and is ridiculously over-commented throughout.

=====

ATSDragToReorderTableViewController relies on UIGestureRecognizer and uses block-based animations throughout. It now has full support for ARC and I'm too lazy to continue to support non-ARC projects so this will be iOS 5+ only from now on.

Licensing info is at the very top of the files as well as in a file called LICENSE.

=====

I am trying to be reserved here but I am pretty excited about this and hope you find this exciting too.

Cheers,
Daniel Shusta

reorderingtableviewcontroller's People

Contributors

shusta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reorderingtableviewcontroller's Issues

problem with integrating into project

According to your readme file, all I have to do to use this module is make my viewcontroller a subclass of ATSDragToReorderTableViewController rather than UITableViewController. My problem is that my viewcontroller currently looks like this:

@interface ViewController_iPad : UIViewController <GKSessionDelegate, UITableViewDelegate, UITableViewDataSource> {
.... other variables
UITableView *playersTableView;
... other variables
}

How should I use your code since i dont originally subclass UITableView? Sorry this may sound like a noob question, but I really need this to add some necessary functionality to my project.

Any feedback would be greatly appreciated.

Thanks

ContentInset makes everything horrible

I was unaware of contentInset when writing this and do not account for this in my code. This can cause the tableview to jump around or autoscrolling to be really weird.

ContentInset will be automatically set if a bar has UIBarStyleTranslucent.

Fix by taking contentInset into account when working with contentOffset

commonInit assertion causes confusion

If you instantiate a UITableViewController that contains a ReorderingTableViewController and then reference its view (in my case in order to make it a subview of my root view), that reference instantiates the tableView. In doing so, the assertion in commonInit also references the view, but apparently before it gets created, so it gets created twice. Or something like that; it's very confusing.

The original symptom I was seeing is that the tableView's reordering gestureRecognizers were disappearing. Turned out that the tableView itself was getting replaced, but with no calls to viewDidLoad/Unload, so the logic for installing our gestureRecognizers failed. I tracked it down, finally, to the assertion.

Commenting out the assertion fixed the problem. If it's really necessary, I suppose it could be safely moved to viewDidLoad.

Drag to empty section

Everything works fine as long as there are other cells in a section, but when you drag all cells away, there is no way to drag them back to the now empty section. Also sections that are empty from the start can't receive dragged cells. Is there a way to make this work?

Tag non-arc version?

Hello,

Thanks for adding a LICENSE so I can make a Podfile.

Would you mind also tagging the previous (non-arc) version as 1.0.0? This way, I can have two versions in CocoaPods available, one that's iOS 5.0+ and one that works with older versions. The command would be...

git tag -a v1.0.0 51e3113

Thanks!
Devin

Possible Extension

Hi, I check this project and I find it very interesting with a great animation fluidity. I have to create something similar but with drag and drop between tables inside the same viewController and between tables in different viewControllers. Do you think it´s possible to start from this project or even if that's a good idea?

Thanks

License

Can you please include a license file so that I can create a pod for this?

Thanks!

feature request: willDrag hook

It would be a convenience to add a delegate call just before the addDraggableIndicatorsToCell: animation block. Something like

dragTableViewController:willDragCell:forIndexPath:

in order to prepare the cell for the drag animation.

Use case: my table cells are borderless images, and the stock shadow tends not to be visible when the images are dark. So I've replaced the shadow effect with a slight enlargement of the cell, which works well. I need to composite an overlay imageview to do this right. I'd prefer to do the compositing in a willDrag call. (My workaround is to always composite the overlay for all cells, and control it with .hidden, which is of course not animatable, so I can get the effect I want by setting it to NO inside the animation block.)

How would I use this with a Table within a UIViewController?

I need to be able to show a table, but not as the whole of the screen.

I would usually do this by making a UIViewController, and sticking a UITableView within the nib, and linking the table to an IBOutlet property, and the delegates and datasource to the class.

@interface CustomViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *listTableView;

How would I do this with the ReorderingTableViewController?

Mac Version

Any way to get this ported to a NSTableView?

blockSelf over-retains self

In ATSDragToReorderTableViewController.m, self got retained when blockSelf is accessed in block, thus self is never deallocated (ARC).

- (void)viewDidLoad {
[super viewDidLoad];

if ( reorderingEnabled )
    [self establishGestures];


/*
 *  If app resigns active while we're dragging, safely complete the drag.
 */
__block ATSDragToReorderTableViewController *blockSelf = self; // self got retained when blockSelf is accessed in block, thus self is never deallocated (ARC)

resignActiveObserver = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillResignActiveNotification object:nil queue:nil usingBlock:^(NSNotification *arg1) {
    if ( [blockSelf isDraggingCell] ) {
        CGPoint currentPoint = [blockSelf->dragGesture translationInView:blockSelf.tableView];
        [blockSelf fastCompleteGesturesWithTranslationPoint:currentPoint];
    }
}];
}

target and proposed destination path

I love what you have done so far, but I have a tableview that has sections and rows that I do not want a cell to move to. To solve this problem in the normal implementation of a UITableView move I would implement: - (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath;
There doesn't seem to be any way to rule out index paths in your current implementation and I tried looking to see where I would do it but a lot of your code is beyond my experience with objective-c. Any pointers as to how I would implement this? Or perhaps you could implement it. But until then, unfortunately, I cannot use this beautiful implementation of moving rows.

Bug: Disappearing and flashing TableViewCells

Hey,

First of all thanks for this neat drag-to-reorder addition!
But I've got some issues with it: Sometimes when I start dragging my TableViewCell will simply disappear (so the overlay that you use to still show it is not visible). When the user drags around, he will see an invisible spot moving.

Another thing that happens often is that when releasing the reordering, the cell released flashes for a split second between two different contents. So it shows the content of another cell, then switching back to its actual (and right) content.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.