GithubHelp home page GithubHelp logo

Comments (9)

shusta avatar shusta commented on September 22, 2024

I didn't want to support that targetIndexPathBlahBlah method because it had the potential to be, well, arbitrarily complicated. For example, I haven't a clue how I would handle something like

return [NSIndexPath indexPathForRow:( proposedDestinationIndexPath.row % 3 ) inSection:0];

But what are you trying to do? There are a couple of common scenarios that I might be able to add. Like a keepWithinSection flag to prevent dragging from one section to another. Or a -dragDelegate:canDragRowFromSourceIndexPath:toDestinationIndexPath: delegate method (return YES if allowed to move there). Would either be useful?

from reorderingtableviewcontroller.

gamemasta0 avatar gamemasta0 commented on September 22, 2024

I would think both could be useful but more useful in my case would be -dragDelegate:canDragRowFromSourceIndexPath:toDestinationIndexPath:
It would accomplish just what I need. Essentially, my situation is: I have an array of items in section 0 with an additional cell to add to the array. and then other sections that cannot be edited but contain relevant information. That is why I want to restrict movement to indexpaths only to section 0 and a row less than the end of the array.

from reorderingtableviewcontroller.

shusta avatar shusta commented on September 22, 2024

(Now that I think about it a bit more, the real problem with -targetIndexPath is that it redirects drag destinations. That's what makes it tricky.)

Sure I could probably add a -canDragRowFromSourceIndexPath:toDestinationIndexPath: delegate method. I don't have time to write it immediately but I'll take a crack at it when my workload lightens a bit.

from reorderingtableviewcontroller.

gamemasta0 avatar gamemasta0 commented on September 22, 2024

Alright, well thank you and I look forward to the update whenever it arrives

from reorderingtableviewcontroller.

jklundell avatar jklundell commented on September 22, 2024

A workaround that I'm contemplating: in keepDraggedCellVisible, I thought I might add an optional delegate call that would return a value to override the default contentRect. Not as convenient as canDrag..., but not too hard to implement, and fully general as long as the permitted target area is contiguous.

Following up. I moved contentRect to its own function, and subclassed it. Worked fine.

from reorderingtableviewcontroller.

shusta avatar shusta commented on September 22, 2024

UITableView's content rect? I'm not clear what you mean.

-- Daniel Shusta

On Jul 1, 2012, at 1:23 AM, Jonathan Lundell [email protected] wrote:

A workaround that I'm contemplating: in keepDraggedCellVisible, I thought I might add an optional delegate call that would return a value to override the default contentRect. Not as convenient as canDrag..., but not too hard to implement, and fully general as long as the permitted target area is contiguous.

Following up. I moved contentRect to its own function, and subclassed it. Worked fine.


Reply to this email directly or view it on GitHub:
#1 (comment)

from reorderingtableviewcontroller.

jklundell avatar jklundell commented on September 22, 2024

I wasn't very clear. In keepDraggedCellVisible, a local variable contentRect is set to the tableview's content. I changed that to call a function that returns that value. So there's no functional change, except that the subclass can override that function and restrict the move to a subset of the tableview.

It's not a completely general solution. It works for me because the tableview I care about is always completely visible (no scrolling), and I can simply return the rect of the section that I'm restricting the move to.

from reorderingtableviewcontroller.

timothyarmes avatar timothyarmes commented on September 22, 2024

The fix to this issue seems trivial - I've just submitted a pull request that seems to we working perfectly to me.

from reorderingtableviewcontroller.

jklundell avatar jklundell commented on September 22, 2024

I ran into a crash with the latest version (23 August 2012). I have a two-section table: data in section 0, and a cell with a + in section 1 that invokes an add-entry sequence. When the user drags a data cell to section 1 (which I don't want to support), we get a crash. The reason: the dragged cell is deleted from section 0 of the table, but the datasource doesn't agree.

The fix was straightforward. No doubt it could be cleaner, but I wanted minimal intrusion for now. We let the delegate veto (by replacement or veto) cells in the covered-cells array.

- (void)shuffleCellsOutOfWayOfDraggedCellIfNeeded {
    /*
        This used to be easy until we started dealing with variable row sizes.

        Now we compare the dragged cell's center with the center of the whole covered rect to determine whether to shuffle.
     */
    NSArray *arrayOfCoveredIndexPaths = [self.tableView indexPathsForRowsInRect:self.draggedCell.frame];
/// PATCH BEGIN
    if ([self.tableView.delegate respondsToSelector:@selector(tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:)]) {
        NSMutableArray *newArrayOfCoveredIndexPaths = [NSMutableArray array];
        for (NSIndexPath *indexPath in arrayOfCoveredIndexPaths) {
            NSIndexPath *newIndexPath = [self.tableView.delegate tableView:self.tableView targetIndexPathForMoveFromRowAtIndexPath:self.indexPathBelowDraggedCell toProposedIndexPath:indexPath];
            if (newIndexPath)
                [newArrayOfCoveredIndexPaths addObject:newIndexPath];
        }
        arrayOfCoveredIndexPaths = newArrayOfCoveredIndexPaths;
    }
/// PATCH END

Please apply.

from reorderingtableviewcontroller.

Related Issues (15)

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.