How to get touch coordinates upon SELECTING a custom UITableViewCell?

When I touch (Touch Up) a UITableViewCell my ViewController's UITableViewDelegate method - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath is called. I need to get the x-coordinate of the Touch-Point at this time as well so that I can know what portion of the Cell was touched (non-accessory items). I have tried using the usual touch methods such as TouchesDidEnd but the coordinates always return x=0.000 y=0.000 no matter where I touched (A location in a custom UITableViewCell in a UITableView object in my ViewController). I also tried implementing touch handling from within the Custom Cell class and while I COULD get accurate coordinates alas I could find no way to communicate those coordinates to my ViewController class (which has the UITableView).

Q: Is there a good way I can get the x-coordinates of the device's screen when I touch a custom UITableViewCell?

Put a transparent UIView atop your table view, override its -touchesBegan:withEvent: etc. methods. In those overridden methods, get the UITouch objects and call -locationInView: on them to get the CGPoint values.

That gives you the coordinates of a touch event.

Then you just pass on those UITouch events to the underlying table view. The table view handles its usual business of passing touches on to rows, etc.

UITableViewController - iOS & Swift Tutorial, Using Custom cells to customize UITableViewCells · Grouping cells into sections: Shift-Click on the table to see all objects at that position and select Table View: In the Attributes Use File » New » File ⌘N to create a new Cocoa Touch Class. Make sure that iOS is selected to create a source file for iOS:. As we’re going to create a new class for the custom table view cell, select “Objective-C class” under “Cocoa Touch” and click “Next”. Create New File for Your Project Fill in “SimpleTableCell” for the class name and select “UITableViewCell” for the “Subclass of” option.

1. Add a tapGestureRecognizer to your tableView

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.tableViewTapped(recognizer:)))

2. Write a function to handle the tapGesture

@objc func tableViewTapped(recognizer: UITapGestureRecognizer) {
    let location = recognizer.location(in: self.tableView) // point of touch in tableView
    if let indexPath = self.tableView.indexPathForRow(at: location) { // indexPath of touch location
        if let cell = tableView.cellForRow(at: indexPath) as? MyCustomCell {
            let locationInCell = recognizer.location(in: cell) // point of touch in cell
            // do something with location or locationInCell

            if cell.imageView.frame.contains(location) || cell.imageView.frame.contains(locationInCell) {
                    print("ImageView inside cell tapped!")        

Handling button tap inside UITableView Cell without using tag, Say you have a button inside every cell in a tableview like this : with message "​Subscribed to [youtuber name]" when user tap on the subscribe the coordinate of the cell tapped to deduce the index, oh god why . the youtuber (Model), you can use your custom model class here var youtuber : String? Hint: In Xcode 11.3 Add New Constraints doesn't allow to enter a distance of 0 anymore. This seems to be a bug in Xcode. To get a margin of 0 create the constraint as described with Standard or some value and edit the constant of the created constraint.

1) Pass view controller object in the custom cell

class ImageTableViewCell: UITableViewCell {

      @IBOutlet weak var img: UIImageView!

      var vc: UIViewController? = nil

      var delegate: TouchLocation?


2) Override the custom table view cell with touchesBegan method, and override super touchesBegan method

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    let touch = touches.first
    delegate?.touchLocation(location: (touch?.location(in:!)
    if let aTouches = touches as? Set<UITouch>, let anEvent = event {
        super.touchesBegan(aTouches, with: anEvent)

3) Get location and pass to view controller using delegation

protocol TouchLocation {
   func touchLocation(location: CGPoint)

extension ImageListViewController: TouchLocation{

   func touchLocation(location: CGPoint) {
         self.touchedPosition = location // Here you will get touch location 


iOS UITableView Custom Cell with Image, Here we will learn ios UI tableview custom cell with images in swift with To select this one, Go to the iOS section on the left side à select Application à In In case if you don't find Object library, click on the button which is at the third position in that choose the “Cocoa Touch Class” and then click on the next button like as  Creating Custom UITableViewCell's with MonoTouch - the correct way Written on 2011-07-18 When I want to create a custom UITableViewCell in a MonoTouch app, I have been using the approach outlined in Simon Guindon's custom UITableViewCell tutorial that he wrote in 2009.

What about :

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        let rect = tableView.rectForRow(at: indexPath as IndexPath)
        var point = CGPoint(x: rect.midX, y: rect.midY)
        point = tableView.convert(point, to: nil)

UITableView Class (UIKit), Working with Tables provides guidance on all aspects of UITableView use. For most a table view. There are four built-in cell types and it is possible to create custom cells both in C# or with Interface Builder. You must subclass this to get a UITableView working. Nothing touched, Highlighted == false ; Selected == false. Hi guys, here's my latest video on implementing a custom table view cell. We'll use a property list to populate a tableview. Then we'll create a custom UITableView Cell to display our results. You

UITableView, Table views on iOS display a single column of vertically scrolling content, or you can group related rows into sections to make navigating the content easier. a simple combination of text and images, but you can define custom cells that the selected row nearest to a specified position in the table view is at that position​. Get absolute position of a UITableViewCell Posted on Published February 14, 2012 February 14, 2012 by Tilo Here’s something that helped me when I was working with WEPopover to implement a popover in my iPhone app a la the iPad.

Handling Row Selection in a Table View, Detect when a user taps a table view cell so your app can take the next If you're using a UITableViewController to display a table view, you get the deselectRow(at: indexPath, animated: false) // Did the user tap on a selected filter item? Customizing a ViewCell. 12/07/2016; 14 minutes to read; In this article. Download the sample. A Xamarin.Forms ViewCell is a cell that can be added to a ListView or TableView, which contains a developer-defined view. This article demonstrates how to create a custom renderer for a ViewCell that's hosted inside a Xamarin.Forms ListView control.

iOS: How to build a Table View with multiple cell types, The are also Table Views with dynamic cells that have different content types: Finally, we have to know what cell type the user taps on and react accordingly. //configure action when tap cell 1 Building the cells is not something I will cover in this tutorial, so you can create your own cell classes, design, and cell layout. You can use ready-made cell objects in a range of styles, you can add your own subviews to the cell object’s content view (which can be done in Interface Builder), or you can use cell objects created from a custom subclass of UITableViewCell. Note that the content view is a container of other views and so displays no content itself.

  • I'm doing so but in this way I'm preventing the uitableview to scroll, any suggestion?
  • this would give you the rect of the cell and not the touch point.
  • @newDeveloper -convertPoint: return a CGPoint... what are you talking about ?
  • your code gets the mid point of the cell's rect. The question was about getting the touch coordinate in the view itself.
  • Good ! the answer I was looking for
  • You code getting points the user tapped on cells, but when user tapped on components in cells it's not getting points