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

Why would self.tempIndexPath ever be nill when moving a view? #2

Open
fresh83 opened this issue Feb 27, 2016 · 1 comment
Open

Why would self.tempIndexPath ever be nill when moving a view? #2

fresh83 opened this issue Feb 27, 2016 · 1 comment

Comments

@fresh83
Copy link

fresh83 commented Feb 27, 2016

Having trouble understanding what this piece of logic is for or what exactly it does/when it would be called:


 if (!self.tempIndexPath) {
            //Why would self.temp be !?


            UITableViewCell *nearstCell = nil;
            NSArray *visibleCells = self.tableView.visibleCells;
            if (visibleCells.count > 0) {
                for (int i = 0; i < visibleCells.count; i++) {
                    UITableViewCell *cell = visibleCells[i];
                    CGPoint cellCenter = [cell.superview convertPoint:cell.center toView:self.tableView];
                    CGFloat top = cellCenter.y - cell.frame.size.height/2.0;

                    //mvTop =220  
                    //topA=0
                    //topB=100
                    //topC=200
                    //topD=300
                    if (mvTop < top) {
                        nearstCell = cell;
                        break;
                    }
                }
                if (!nearstCell) {

                    NSMutableArray *daySectionArray=[self.sortedTasksArray objectAtIndex:0];

                    [daySectionArray addObject:theMovingView.userInfo[@"object"]];

                    [self.sortedTasksArray replaceObjectAtIndex:self.tempIndexPath.section withObject:daySectionArray];


                    NSIndexPath *upperIndexPath = [NSIndexPath indexPathForRow:[self.tableView numberOfRowsInSection:0] inSection:0];
                    self.tempIndexPath = upperIndexPath;
                    [self.tableView insertRowsAtIndexPaths:@[self.tempIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
                } else {
                    NSIndexPath *upperIndexPath = [self.tableView indexPathForCell:nearstCell];
                    [self.tableView beginUpdates];
                    id object = theMovingView.userInfo[@"object"];

                    NSMutableArray *daySectionArray=[self.sortedTasksArray objectAtIndex:upperIndexPath.section];

                    [daySectionArray insertObject:object atIndex:upperIndexPath.row - 1];
                    [self.sortedTasksArray replaceObjectAtIndex:upperIndexPath.section withObject:daySectionArray];

                    NSIndexPath *tempIP = [NSIndexPath indexPathForRow:upperIndexPath.row - 1 inSection:upperIndexPath.section];
                    self.tempIndexPath = tempIP;
                    [self.tableView insertRowsAtIndexPaths:@[tempIP] withRowAnimation:UITableViewRowAnimationAutomatic];
                    [self.tableView endUpdates];
                }
            } else {
                NSMutableArray *daySectionArray=[self.sortedTasksArray objectAtIndex:self.tempIndexPath.section];


                [daySectionArray addObject:theMovingView.userInfo[@"object"]];

                [self.sortedTasksArray replaceObjectAtIndex:self.tempIndexPath.section withObject:daySectionArray];


                NSIndexPath *upperIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
                self.tempIndexPath = upperIndexPath;
                [self.tableView insertRowsAtIndexPaths:@[self.tempIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
            }
        }
@WeeTom
Copy link
Owner

WeeTom commented Apr 26, 2017

@fresh83 Sorry for this late reply.
self.tempIndexPath is used to show a shadow in the TableViewController. So that we can see the future location.
This can be nil, when the moving item is first moved to be in the new TableViewController.
And when it is nil, we start to find the nearest location inside the TableViewController.
image

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