I have 2 segmented controls in my viewcontroller view. How can I handle the tap events of both of the segmented controllers?
There are two ways to do so.
Add same actions for every segment control & check which control is tapped using its tag.
[yourSegmentedControl addTarget:self action:@selector(segmentSwitch:) forControlEvents:UIControlEventValueChanged];
- (IBAction)segmentSwitch:(id)sender
{
UISegmentedControl *segmentedControl = (UISegmentedControl *) sender;
if(segmentedControl.tag == someTag)
{
if(segmentedControl.selectedSegmentIndex == 1)
{
// your code
}
else if(segmentedControl.selectedSegmentIndex == 2)
{
// your code
}
}
else if(segmentedControl.tag == someTag)
{
if(segmentedControl.selectedSegmentIndex == 1)
{
// your code
}
else if(segmentedControl.selectedSegmentIndex == 2)
{
// your code
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With