分割ビューの左パネルのテーブルビューから右パネルの詳細画面に行をドラッグするために使用するコードを次に示します。確かに同一ではありませんが、これはあなたの問題に似ているようです。とにかく、私は個人的に長押しからドラッグアンドドロップをトリガーします:
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
[self.tableView addGestureRecognizer:longPress];
そして、私のハンドラーは次のことを行います。
- (IBAction)longPress:(UIGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateBegan)
{
// figure out which item in the table was selected
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:[sender locationInView:self.tableView]];
if (!indexPath)
{
_inDrag = NO;
return;
}
_inDrag = YES;
// get the text of the item to be dragged
NSString *text = [NSString stringWithString:[[_objects objectAtIndex:indexPath.row] description]];
// create item to be dragged, in this example, just a simple UILabel
UIView *splitView = self.splitViewController.view;
CGPoint point = [sender locationInView:splitView];
UIFont *font = [UIFont systemFontOfSize:12];
CGSize size = [text sizeWithFont:font];
CGRect frame = CGRectMake(point.x - (size.width / 2.0), point.y - (size.height / 2.0), size.width, size.height);
_draggedView = [[UILabel alloc] initWithFrame:frame];
[_draggedView setFont:font];
[_draggedView setText:text];
[_draggedView setBackgroundColor:[UIColor clearColor]];
// now add the item to the view
[splitView addSubview:_draggedView];
}
else if (sender.state == UIGestureRecognizerStateChanged && _inDrag)
{
// we dragged it, so let's update the coordinates of the dragged view
UIView *splitView = self.splitViewController.view;
CGPoint point = [sender locationInView:splitView];
_draggedView.center = point;
}
else if (sender.state == UIGestureRecognizerStateEnded && _inDrag)
{
// we dropped, so remove it from the view
[_draggedView removeFromSuperview];
// and let's figure out where we dropped it
UIView *detailView = self.detailViewController.view;
CGPoint point = [sender locationInView:detailView];
UIAlertView *alert;
if (CGRectContainsPoint(detailView.bounds, point))
alert = [[UIAlertView alloc] initWithTitle:@"dropped in details view" message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
else
alert = [[UIAlertView alloc] initWithTitle:@"dropped outside details view" message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}
}