UIButton events

Discussion in 'iOS Programming' started by aukemid, Nov 19, 2010.

  1. aukemid macrumors newbie

    Joined:
    Mar 26, 2010
    #1
    I have a UITableView and the rows in this contain buttons.
    Now the buttons call a method on the Touch up inside event and when a button is pressed down the table doesn't scroll.

    The buttons should only react if the touch doesn't move, so only if I press and release at the same spot. If the touch does move I would like the table to scroll.

    Is this possible? Is there a button event that works like this? Can I detect a swipe in the table if it's done over the buttons? And does anyone has example code?
     
  2. yaniv92648 macrumors member

    Joined:
    Oct 26, 2009
    #2
    It's quite easy to implement..

    Though u can't do that with a UIButton.
    create a class MyButton that inherits UIImageView (i'm guessing u want an image there). implement the UIView touch methods in the class,
    declare a BOOL variable touchMoved and do the following:
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    touchMoved = NO;
    }
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    touchMoved = YES;
    }
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    if(!touchMoved){
    // Do what u wanna do
    }
    }
     

Share This Page