tags:

views:

213

answers:

1

Dear All,

I tried to find an easy solution for the following. I have a main view which holds a tile. I want to drag and drop it over a UITableView. I could program the pick and drag already with UIGestureRecognizer.

Now my problem is how can I detect within the table view that there is an item going to be dragged above it. For instance I want to highlight the given row when the tile is moved above it.

I tried to add the touchesMoved/Began/Ended events to the viewCell. They does not get fires when I am dragging the tile over it (in other words the tile is hiding a portion of the viewCell under my finger). They get fired when there is no tile dragged above.

Is there an effective hittest method for that?

Thanks.

A: 

There are a whole bunch of UI issues here that should be addressed.

  • In general, Drag and drop on the iPhone is a BAD idea. It's very hard to do, and getting feedback is going to be problematic, because your finger will be obstructing the drag operation
  • using the table's selected cell to indicate 'dropability' may get you rejected by the app store reviewers; it's to indicate "I've selected this cell", not "I'll drop something onto it"

That said, you'll probably want to manage all your touch events in the 'source' view, and send the table messages from there, rather than trying to juggle messages around. Once your -touchesBegan:withEvent: has been called in one view, all subsequent -touchesMoved:withEvent: and -touchesEnded:withEvent: will be sent to that view for the life-cycle of that touch; forwarding them around will confuse the heck out of everyone involved.

Ben Gottlieb
Thanks Ben for the answer. For the first part: my app is going to be an iPad app. For the second part: I do not understand what you mean.To make my question simple: I want to drag and drop a photo on a tableview row. I start the drag. Works perfectly. However cellview's touchesBegan/Moved/Ended are not being called when I drag the photo over them.So how do I know which row is going to get the drop?
Teddy
You'll need to calculate that by looking at the frame of each cell in the table. Maybe a -cellForPoint: method on your table or viewController.
Ben Gottlieb
Thank you Ben that is the solution came up with finally. I was hoping for a shorter solution.Thanks again.
Teddy