Get on screen coordinates of a certain UITableViewCell? - iphone

So, I have this UITableView. It's in an iPad application. Some of the cells have an accessory button on the right (the small round arrow). When that is pressed, I present a popover view where the user can select actions related to the table cell that they touched. So far, nothing of this is difficult or exceptional.
But the popover view wants to know where it originates from, so that it can draw the little arrow pointing there. I would naturally like that arrow to point at the table cell the popover relates to.
How can I find out the current on screen coordinates for a certain cell in a table, given that I know it's indexPath?

Use the UITableView method -rectForRowAtIndexPath:. Note that that returns a rect within the table view’s coordinate system—if you need the rect relative to another view within the same window, use the UIView method -convertRect:fromView:.

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.

Display UITableView's section title when index is touched

I'm writing a dictionary app to study iOS and I've implemented a UITableView with the alphabet as section titles and an index of all the letters on the right side. It works perfectly, but is it possible for me to display the selected index in a box at the center of the screen? I'm looking at the UITableViewDelegate reference but can't see any methods I might override. Help?
You'd have to manually create a UIView that you put above the UITableView which then shows the letter or whatever you want to present. Make sure not to add it to the table view itself as it's a UIScrollView subclass and your view would be affected by its contentOffset.
When the user presses one index or moves his finger above it, this callback gets called:
-tableView:sectionForSectionIndexTitle:title atIndex:
Use it to change your view's contents and make it visible and set a timer for it to fade out again.
You have to create custom view that display when you click on the cell and in that view you can add Label to show the alphabet which you have selected.
And yes also if you want to display it on center of your screen than give its X and Y coordinates value according to it.hope it helps...

UITableView should go beyond its frame when scrolled

Am trying out an example app using UITableView.
The upper (nearly) half of the screen is filled by a UIView which has some components like button, text field, and an image view. The lower half (In IB, its width=320 and height=234 pixels) is filled by a UITableView instance.
Am using custom UITableViewCell objects to be displayed within this UITableView.
This is the size definition of the UITableView instance in IB:
And this is the size definition for the UITableViewCell:
I have defined two types of custom UITableView cells that can be placed in the UITableView (and the decision of which type is decided dynamically based on whether the cell has a picture to be displayed, or not). Cells with picture are bigger and have a different layout than those without. The custom UITableViewCell which has a picture has these size parameters in IB (the height '301' is more than that for the generic UITableViewCell instance '234' specified in the main Storyboard in the screenshot above of the entire screen):
Now, when I run the app and scroll the table view, the table view needs to scroll along the entire screen (i.e. the first half of the screen that has a UIView with she components should also scroll away), just like in the Path app like this:
This is the initial screen in the Path App: (the top half is some fixed UIView and those below in the 2nd half of the screen is the timeline, which is a UITableView)
When you start scrolling the timeline, the upper half also scrolls away:
How can I do this (i.e the top half also scrolls away)?
I tried adding a UIScrollView to the entire screen and put it behind all the other components in the screen, but this didn't help.
Can someone please suggest ? or any pointers?
Make the UITableView take up the entire screen, and add your view that now takes the top half as the headerView of the table view (you can just drag it ontop of it in the interface builder and it should snap right in).

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,

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.