Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to create an event depending of the number of touches in a tableView?

RomuloVielRomuloViel USMember ✭✭

This is my code, but something is going wrong
the tap code is doing nothing...

If I delete or no the app don't count the taps!

I tap 1 time, nothing is show on the output, if I tap 2 the same...

` public override void RowSelected (UITableView tableView, NSIndexPath indexPath) {

        CBCharacteristic characteristic = this._characteristics [indexPath.Row];
        this.CharacteristicSelected (this, new CharacteristicSelectedEventArgs (characteristic));

        NSSet touches = new NSSet();
        UITouch touch = touches.AnyObject as UITouch;

            if (touch != null) {

        if (touch.TapCount == 1) {

                if (touch.TapCount == 2) {


        tableView.DeselectRow (indexPath, true);


Best Answer


  • adamkempadamkemp USInsider, Developer Group Leader mod

    This is a duplicate of another post (, but you included more information so I'll respond here.

    This code obviously won't work. It looks like you copy/pasted some code from somewhere without understanding how it worked, and then you just tried to make it compile. All you're doing here is creating an empty set and then asking for the first object (which is obviously going to be null since the set is empty). Then you're doing something with the first object if it isn't null. That code will never execute because, again, that object is guaranteed to be null.

    The code you're trying to use is designed to be used as part of touch processing, where you would somehow receive that set of touches or a specific touch as an argument. RowSelected doesn't give you that. RowSelected is called by the table view, which does its own touch processing and only gives you a notification of what happened.

    There are ways to do this (which you can find on stack overflow if you search), but I strongly discourage you from making this part of your app. Users never expect double tapping a row in a table view to do anything. Table views are recognizable, and therefore users have expectations about how they behave and which gestures will work for them. Double tap isn't one of those gestures. If you rely on double tap for a table view row your app will be confusing.

    A better approach is to use a DetailDisclosureButton accessory type. This gives your cell a button on the right that users can tap. Tapping that button gives you a different event than tapping the row itself. You would add it like this:

    // in GetCell
    cell.AccessoryType = UITableViewCellAccessory.DetailDisclosureButton;

    Then override AccessoryButtonTapped to handle the button being pressed.

  • RomuloVielRomuloViel USMember ✭✭
    edited August 2014

    Actually, this is part of my code. This was just a test. I deleted things unrelated to my doubts, I just forgot the first few lines.
    But the point is that I wanted to do was a request from the person who wants the app.
    Before I was using UIAlertView. When the line was selected the pop-up appeared with the buttons, but the person did not like.

    I could not understand why you say that the object is null ...

    How do I do to implement two buttons per row?

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Look at this code:

        NSSet touches = new NSSet();
        UITouch touch = touches.AnyObject as UITouch;

    touch is guaranteed to be null. If these lines are different in your real app then where are you getting the set of touches from? RowSelected doesn't give you the touches.

    You should read this:

  • RomuloVielRomuloViel USMember ✭✭
    edited August 2014

    I was trying to override the method "TouchesBegan" but he doesn't exist, I can't override it.
    I follow this by the Xamarins site..

    I do not know where's my error...

    I saw it on Cross-plataform. This is why I can't override the method!

  • RomuloVielRomuloViel USMember ✭✭

    Yeah, I'm agree with you.. My original Ideia was with UIAlertView!
    I will try talk with him again.

Sign In or Register to comment.