2
votes

I have a situation i have a UIButton Class in which upon selecting a button i am getting the id of the buttton based upon it i am changing the color of the button by using [self addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

And by using touchesBegan, touchesMoved, touchesEnded method i can drag drop the button object to any part of screen.

Now the problem is if i uses touchesBegan, touchesMoved, touchesEnded method then i am not getting id of button so i am not able to change the color.

So how can i able to get both the problem solved?

2

2 Answers

1
votes

one of the parameters for touchesBegan is a set of UITouch objects. UITouch has property "view", which is the view that you tapped on. So something like

-(void)touchesBegan:touches withEvent:e
{
    id* myButton = [touches anyObject].view;
}
0
votes

If you call the following method on your parent view (containing all the buttons) in touchesBegan: it should return you the button you are touching....

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

Hope this helps.