Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to drag UITableViewCell and drop it to another UITableView?
    primarykey
    data
    text
    <p>I was able to get only partial output, main functionality of drag and drop was achieved but it was crashing some times and showing error as index out of bounds.</p> <p>I use pan gesture controller to drag and drop the UITableView cell, I also want to know how it can be done by using touches began,touches moved and touches ended method.</p> <p>This is my sample code</p> <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { pathNumber=indexPath.row; cell = [tableView cellForRowAtIndexPath:indexPath]; UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetected:)]; [cell addGestureRecognizer:panRecognizer]; if (cell.accessoryType==UITableViewCellAccessoryNone) { cell.accessoryType = UITableViewCellAccessoryCheckmark; if(tableView==tableView1) { [selectedCells addObject:[array objectAtIndex:indexPath.row]]; NSLog(@"indexpath-%d",indexPath.row); [arrayOfPaths addObject:indexPath]; NSLog(@"----%@",selectedCells); NSLog(@"----======%@",arrayOfPaths); } else { [selectedCells1 addObject:[array1 objectAtIndex:indexPath.row]]; NSLog(@"indexpath-%d",indexPath.row); [arrayOfPaths1 addObject:indexPath]; NSLog(@"====%@",selectedCells1); NSLog(@"----======]]]]]%@",arrayOfPaths1); } } else { cell.accessoryType = UITableViewCellAccessoryNone; if(tableView==tableView1) { [selectedCells removeObject:[array objectAtIndex:indexPath.row]]; [arrayOfPaths removeObject:indexPath]; NSLog(@"----%@",selectedCells); NSLog(@"----======remove%@",arrayOfPaths); } else { [selectedCells1 removeObject:[array1 objectAtIndex:indexPath.row]]; [arrayOfPaths1 removeObject:indexPath]; NSLog(@"====%@",selectedCells1); NSLog(@"----======remove1%@",arrayOfPaths1); } } } - (void)panDetected:(UIPanGestureRecognizer *)panRecognizer { CGPoint translation = [panRecognizer translationInView:self.view]; CGPoint cellViewPosition = cell.center; cellViewPosition.x += translation.x; cellViewPosition.y += translation.y; cell.center = cellViewPosition; [self.view bringSubviewToFront:cell]; [panRecognizer setTranslation:CGPointZero inView:self.view]; NSArray * arr=[NSArray arrayWithObject:[NSIndexPath indexPathForRow:pathNumber inSection:0]]; NSArray * arr1=[NSArray arrayWithObject:[NSIndexPath indexPathForRow:pathNumber inSection:0]]; if(panRecognizer.state==UIGestureRecognizerStateBegan) { position1=[panRecognizer locationInView:self.view]; } if(panRecognizer.state==UIGestureRecognizerStateEnded) { position = [panRecognizer locationInView:self.view]; NSLog(@"%f %f",position.x,position.y); if(CGRectContainsPoint(tableView2.frame, position)) { NSLog(@"1-2"); if(position.x&gt;=tableView2.frame.origin.x &amp;&amp; position1.x &gt;= tableView1.frame.origin.x &amp;&amp; position1.x &lt;= tableView1.frame.size.width) { if([selectedCells count] ==1) { [tableView2 beginUpdates]; [tableView2 insertRowsAtIndexPaths:arr1 withRowAnimation:UITableViewRowAnimationTop]; [array1 insertObject:[array objectAtIndex:pathNumber] atIndex:pathNumber]; d=[array1 count]; [tableView2 endUpdates]; [tableView1 beginUpdates]; [tableView1 deleteRowsAtIndexPaths:arr withRowAnimation:UITableViewRowAnimationTop]; [array removeObjectAtIndex:pathNumber]; c=[array count]; [tableView1 endUpdates]; } else { [tableView2 beginUpdates]; [tableView2 insertRowsAtIndexPaths:arrayOfPaths withRowAnimation:UITableViewRowAnimationTop]; for(int j=0;j&lt;[arrayOfPaths count];j++) { NSIndexPath * tempIndexPath = (NSIndexPath *)([arrayOfPaths objectAtIndex:j]); [array1 insertObject:[selectedCells objectAtIndex:j] atIndex:tempIndexPath.row]; } d=[array1 count]; NSLog(@"%d", d); [tableView2 endUpdates]; [tableView1 beginUpdates]; [tableView1 deleteRowsAtIndexPaths:arrayOfPaths withRowAnimation:UITableViewRowAnimationTop]; for(int j = 0;j &lt; [arrayOfPaths count]; j++) { NSIndexPath * temp = (NSIndexPath *)[arrayOfPaths objectAtIndex:j]; [array removeObjectAtIndex:temp.row]; } c=[array count]; [tableView1 endUpdates]; } [selectedCells removeAllObjects]; [arrayOfPaths removeAllObjects]; } else { NSLog(@"else"); } } else if(CGRectContainsPoint(tableView1.frame, position)) { NSLog(@"hi-2"); if(position.x&gt;=tableView1.frame.origin.x &amp;&amp; position1.x &gt;= tableView2.frame.origin.x &amp;&amp; position1.x &lt;= tableView2.frame.size.width + tableView2.frame.origin.x) { if([selectedCells1 count] == 1) { [tableView1 beginUpdates]; [tableView1 insertRowsAtIndexPaths:arr1 withRowAnimation:UITableViewRowAnimationTop]; [array insertObject:[array1 objectAtIndex:pathNumber] atIndex:pathNumber]; c=[array count]; [tableView1 endUpdates]; [tableView2 beginUpdates]; [tableView2 deleteRowsAtIndexPaths:arr withRowAnimation:UITableViewRowAnimationTop]; [array1 removeObjectAtIndex:pathNumber]; d=[array1 count]; [tableView2 endUpdates]; } else { [tableView1 beginUpdates]; [tableView1 insertRowsAtIndexPaths:arrayOfPaths1 withRowAnimation:UITableViewRowAnimationTop]; for(int j=0;j&lt;[arrayOfPaths1 count];j++) { NSIndexPath * tempIndexPath = (NSIndexPath *)([arrayOfPaths1 objectAtIndex:j]); [array insertObject:[selectedCells1 objectAtIndex:j] atIndex:tempIndexPath.row]; } c=[array count]; NSLog(@"%d", c); [tableView1 endUpdates]; [tableView2 beginUpdates]; [tableView2 deleteRowsAtIndexPaths:arrayOfPaths1 withRowAnimation:UITableViewRowAnimationTop]; for(int j = 0;j &lt; [arrayOfPaths1 count]; j++) { NSIndexPath * temp = (NSIndexPath *)[arrayOfPaths1 objectAtIndex:j]; [array1 removeObjectAtIndex:temp.row]; } d=[array1 count]; [tableView2 endUpdates]; } [selectedCells1 removeAllObjects]; [arrayOfPaths1 removeAllObjects]; } else { NSLog(@"else1"); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload