Hope someone can help - I have searched high and low for and answer to this scenario and have found some related ideas, but nothing concrete yet:
I have a UIView with multiple UIButtons as subviews (sitting above the parent UIView). I have assigned unique Tags to the UIButtons.
I want to handle the following scenario:
Touch down event in one UIButton (and get Tag), drag finger, and then touch up event in another UIButton (and get new Tag).
At the moment the touch up event returns the Tag of the first UIButton wherever I lift my finger on the screen (i.e. within the first UIButton which is what I would expect, or in a second UIButton, or in the gap between buttons (the parent UIView)). I would expect the latter two touch up events to return the Tags of the second UIButton or parent UIView respectively.
Here's the UIButton creation code (inside a loop):
Code:
UIButton *nButton = [UIButton buttonWithType:UIButtonTypeCustom];
[nButton addTarget:self action:@selector(nodeButtonPressed:) forControlEvents:UIControlEventTouchDown];
[nButton addTarget:self action:@selector(nodeButtonReleased:) forControlEvents:UIControlEventTouchUpInside];
// I set other button parameters here...
[self.view addSubview:nButton];
And in the two selector functions I am just reading the Tag of the sender, e.g.:
Code:
- (IBAction)nodeButtonReleased:(id)sender
{
UIButton *nodeButton = (UIButton *)sender;
int nodeId = nodeButton.tag;
NSLog(@"%i", nodeId);
}
Any guidance?
Thanks,
Rich