I have two UISwitch, both call the same method on the click event, so in that methodi need to distinguish between the two switch to know who send the event. For that i assigned tag only for one of them:
switch1.tag=0;
In the method that gets fired when one of these UISwitch gets clicked, i make that test:
-(void)switchValueGetsChanged:(UISwitch*)sender{
if (sender.tag==0) {
NSLog(@"It's switch 1");
}else{
NSLog(@"It's switch 2");
}
Now, when i run the code, what i noticed is that i get always the first message:
NSLog(@"It's switch 1");
Even when i click on the second UISwitch. I solved the issue by assigning a tag for the second UISwitch as well:
switch1.tag=0;
switch2.tag=1;
Now, the problem is solved, so my question is: if you get more than one UISwitch, and you want to judge on the tag value, is it mandatory to assign tag property for all your UISwitchobjects ? Thanx in advance.
You asked:
If you want to differentiate any view based on its
tagproperty then yes, you must set itstagproperty. How else could you check thetagif you don’t set thetag?BTW – don’t use
0as one of your tag values. This is the default for all views so setting it to0doesn’t really help any.