I have a UIViewController that has both a UITable and a UIView on it. I want to be able to pick up items that are displayed in the UIView and drop them on to a cell in the UITableView.I have had to revert to using touch events as opposed to the new UIGestureRecognisers to take a snap shot of the UIView tapped so that this snap shot is dragged over to the UITableView as opposed to the UIView touched. This works great using the following,
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *t =[touches anyObject];
UIGraphicsBeginImageContext(t.view.bounds.size);
[t.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.draggedView = [[UIImageView alloc] initWithImage:img];
CGPoint centre = [[touches anyObject] locationInView:self.view];
[self.draggedView setCenter:centre];
[self.draggedView setAlpha:0.5];
[self.view addSubview:self.draggedView];
}
However, in the touchesEnded event when I try to evaluate which UIView the touch ended on I always get a UIView instead of the UITableView when I drop on it. Any ideas would be very welcome.
I think I have come up with better solution to this problem using the latest GestureRecognisers. I use the following LongPress Gesture Recogniser inside my base TableView Controller.
In the TableViews that extend this base class I add the following to each cell in the cellForIndexPath TableViewDataSource,
and finally all you need to do is implement the delegate methods like so,
You can find the source for this here. It took me a long time to get this right so I really hope this saves someone else the time.