UITableView: Drag a row onto another one - iphone

I have a UITableView that represents a list of objects, I'd like the user to touch an object, drag it onto another one (as to combine them) and seeing the two disappearing and a new one appearing. I guess that I can't do this with the standard table view editing methods (a row cannot be dragged onto another one, am I right?). Shall I write my touch listeners? how can I do that?

I managed to find a workaround: after the first click on a custom UITableCellView I create a new UIView to put on top of the window that intercepts another touch+drag.
The other touch creates a UIImageView that copies the undelying clicked cell as a Image. This UIImageView can be dragged around along the UIView and then dismissed when necessary.
When I end the touch I look if it ended up a another cell, if so I get its indexPath and compute a coherent action

Related

drag and drop from uitableviewcell to uiimage view in ios

I need help implementing a drag and drop gesture, I would like to know Your opinion to find the best approach.
I have a view controller with a uitableview on the right and some image views on the left.
I would like to allow the user to drag every cell of the table view on one of the image views. Basically the drag-n-drop will fail if the cell is not released on one of the image views, otherwise the image view will change image according to the dropped cell.
What do You think is the best way to achieve this?
In addition, when the user start dragging, I would like that he drags around a particular shaped subview, with image and data, not drag the semitransparent cell.
Thanks,
The basic steps for this would be:
Add a long press gesture recognizer to your table view (the whole view, not individual cells)
When the gesture begins, find which cell it is over (convert point, then user indexPathForRowAtPoint to get the cell)
Make a copy of that cell which will become the dragged view (take a snapshot, add it to a UIImageView and add that to your main view). Or you could make the view look however you want if you dont want it to look like the cell
make your original cell hidden so it looks like it is being dragged
On gesture changed, move teh position of this image view based on locationInView of the gesture)
On gesture ended, check to see if the cell is over an image (hitTest: for this) and do any animations or calculations you need.

iOS - UITableView Pan Gestures

This may turn out to be 2 questions in one, but I believe solving the first will go most of the way to solving the second.
First, I have created a view in Interface Builder (I know!) and I load the xib file into my view controller in the app delegate. All of this runs smoothly and as expected.
The view consists of 3 table views, two of a similar size and one small one in a corner.
A cell is added to one table view a pan gesture is added to allow movement around the scene.
However, if a cell is moved from it's table view, it appears to go BEHIND the parent view, as per the screenshot below:
The grey line between the two tables is the gray background of the parent view. If the user still has his/her mitts on the cell, they can drag it into view but how can I make it so that all table views are on the same 'layer'?
I.e. so that dragging a cell from one table view to another with show the cell hovering over both views.
This leads me onto my second question, which I will not ask yet as I believe the solution to this will solve my current issue. but I will explain for further clarity.
In my pan gesture, I use a point inside check to see if the cell is within a table view, currently panning a cell from any table makes it print. It is almost like the views take up the whole screen, even though they are sized not to?
All ideas welcome! Thanks!
This was solved by listening for the cell leaving the bounds of the table view, when this happened, I transferred the cell across the table view that it has been dragged to, adding it to the bottom of the list.
Not the most elegant solution and you do lose the touch but it does work,

Is it possible to put one UITableView over another UITableView in InterfaceBuilder?

I know I can use codes to add UITableView one by one.
[self.view addSubview:tableview1];//
[self.view addSubview:tableview2];//
I hope to do the same thing in InterfaceBuilder, when I drag one UITableView onto another one, the new one always pushes the old one to the bottom, rather than just stays over the old one of UITableView.
Welcome any comment
Thanks
If you have a parent view that will contain your tableviews then you shouldn't have any problem. If you're trying to place them directly in a window then I could see a problem. If things aren't lining up the way you want you can always change their position via the Size Inspector or by nudging them with the arrow keys (shift-arrow key moves in 10 pixel increments).
Why anyone would want a tableview on top of another tableview escapes me.
Your parent view should be a subclass of uiviewcontroller and your xib should have the root view as a uiview and not uitableview.
I used two overlapping table views to show two different contents on the same view, which could be toggles using a segment switch. Apparently my client requirements were vague enough that I couldn't just filter out data like how the phone app displays all calls/missed calls list.

Best way to avoid memory leaks for Multiple Buttons in UITableViewCell

I've got an array of buttons in a UITableViewCell.
I populated them all through the cellForRowAtIndexPath method, but my tableview gets sluggish even though I have released everything.
Should I be using a custom UITableViewCell to populate?
Any suggestions on how to make this as smooth as possible for the user would be great.
Screenshot below.
You could create a custom cell / custom view pair for this specific cell, where you can draw all yours buttons in drawRect:. However, this would essentially draw all your buttons as an image so you wouldn't be able to tap them, but I guess you can always create a UITapGestureRecognizer to your cell (you'd still have to figure out which button was pressed by examining x,y values).
Still, I don't see any point in adding your tag buttons inside a UITableViewCell. You could come up for an alternate design in your UI, i.e. a UIView presented on top of the table, or a modal controller maybe.

How do you drag-and-drop from a TableView's icon to a stationary icon?

How do we go about coding drag-and-drop (or tap-and-drag) from a cell in a TableView on an iPhone? I'd like to have a set of drop destination icons that are stationary. I've been trying touchesBegan, touchesMoved and touchedEnded methods. These events fire nicely from a View so I can get a swipe to work nicely. Most likely the destination icons will be in a View so I think we are trying to get the drag-and-drop to begin in a TableView cell and end on an icon on a View that is beside the TableView.
Are you trying to drag the entire UITableViewCell, or a UIView inside the cell? Either way, I don't think you'll be able to move the view outside the bounds of its parent, which would be the UITableView.
I have another project where I have a icon or tile (UIImageView) that the user can drag around the screen. After it reaches a certain distance, it snaps back.
Similarly, a possible solution might involve popping up a UIView (perhaps a UIImageView) over top of the table cell when the cell is tapped. The user could drag that around the screen, and you could make it disappear when it's "dropped" on whatever target you have.