How to implement two IBActions in UIButton without overlap?
ibaction, ios, objective-c, uibutton
Solution
i have solved a problem like this with using drag Events
add events to your button in .xib file or programatically.
programmatically is:
[mybut addTarget:self action:@selector(dragBegan:withEvent: )
forControlEvents: UIControlEventTouchDown];
[mybut addTarget:self action:@selector(dragMoving:withEvent: )
forControlEvents: UIControlEventTouchDragInside];
[mybut addTarget:self action:@selector(dragEnded:withEvent: )
forControlEvents: UIControlEventTouchUpInside |
UIControlEventTouchUpOutside];
then defininitons of events are:
- (void) dragBegan: (UIButton *) c withEvent:ev
{
NSLog(@"dragBegan......");
count=NO;//bool Value to decide the Down Event
c.tag=0;
[self performSelector:@selector(DownSelected:) withObject:mybut afterDelay:0.1];
//user must begin dragging in 0.1 second else touchDownEvent happens
}
- (void) dragMoving: (UIButton *) c withEvent:ev
{
NSLog(@"dragMoving..............");
c.tag++;
}
- (void) dragEnded: (UIButton *) c withEvent:ev
{
NSLog(@"dragEnded..............");
if (c.tag>0 && !count)
{
NSLog(@"make drag events");
}
}
-(void)DownSelected:(UIButton *)c
{
if (c.tag==0) {
NSLog(@"DownEvent");
count=YES;//count made Yes To interrupt drag event
}
}
Problem
I drag 2 IBActions from a `UIButton`, one with touchDown event and second with drag Inside. ``` - (IBAction)clickButton:(UIButton *)sender { NSLog(@"Click Button"); } - (IBAction)dragInsideButton:(UIButton *)sender { NSLog(@"Drag Button"); } ``` But when I drag inside, the touchDown action also gets fired. How to disable touchDown event when dragInside. Thanks!