0

I want to drag from the masterview tableview Cell to DetailView.

I try with touchesBegan & touchesEnded method but not working.

Can you please help me for this?

Thank you

2 Answers2

1

This is actually not easy. You can start by

  1. Adding a pan gesture recognizer (UIPanGestureRecognizer) to the root view controller's view (UIWindow.keyWindow!.rootViewController!.view).

  2. When the pan starts (i.e. user touches the screen), loop through the master view's table view's visible cells to see if the point is inside any cell by using UIView's convertPoint:fromView:. You may need to adjust timing to avoid interfering with table view's scrolling and tapping.

  3. If a cell contains the pan's point, create an "indicator view" (that shows that user is dragging) and add it to the root view controller's view, on top of everything else and position it properly, e.g. under user's finger.

  4. When the pan changes (i.e. user moves his finger), update the indicator view's location.

  5. When the pan ends (i.e. user releases his finger), check if the point is inside the detail view and do whatever you need to do.

Check this out. It demonstrates how to do drag drop within a view. Your problem is more complicated as it involves different view controllers, hence the touch handling must be done at a level higher than both master and detail view controllers.

Community
  • 1
  • 1
Khanh Nguyen
  • 11,112
  • 10
  • 52
  • 65
0

Why are you using touchesBegan & touchesEnded methods? If you have the tableView you should use didSelectRowAtIndexPath delegate method. And you can also use segues if you are using storyboards.

Gurdev Singh
  • 1,996
  • 13
  • 11