There are two segmental controls in my viewcontroller. How can I handle the tap events of both segmented controllers?
Set the tag property for each segmental control for another integer. Then, in your method, which you set as an action, when the value changes, check the integer value of the tag property using [sender tag] .
tag
[sender tag]
There are two ways to do this.
Add the same actions for each segment control and check which control is used with 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 } } }
Apple docs says:
http://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UISegmentedControl_Class/Reference/UISegmentedControl.html
You register target action methods for the segmented control using the UIControlEventValueChanged constant, as shown below.
[segmentedControl addTarget:self action:@selector(action:) forControlEvents:UIControlEventValueChanged];
So, you just need to register an action for each segmented control.
You can use the selected segment mode:
UISegmentedControl *tempSegment = sender; if ([tempSegment selectedSegmentIndex] == 0){ //first Action } else if ([tempSegment selectedSegmentIndex] == 1){ //second Action }
Assign two different actions to these segmented controls:
Quick version:
@IBAction func yourFunctionName(sender: UISegmentedControl) { if (sender.selectedSegmentIndex == 0){//choice 1 }else{//choice 2 } }
Source: https://habr.com/ru/post/1382998/More articles:loop through gridview and get data key value - vb.netjQuery delegation inside div> divs> a also :( - javascriptCompiling code in Visual Studio that does not require the installation of .net C ++ - c ++Iterate over iPhone Address book calling address book sql db corrupt - iosset an alarm at the selected time and date - androidJQuery-Mobile: how to deploy a sample application on a device - jquery-mobileAuthorize root mode when device is rotated - xcodeA linked object is never null - c #How to get the name of the news Article in GoogleNewsSitemap using kentico CMS - asp.netWhy doesn't Ocsigen run my python file? - ocamlAll Articles