0

I'm using a single action to handle 10 UISwitches by sending a tag value to it. I have a number of integers initialised when launched thus;

int switch_1 = 0; int switch_2 = 0; etc

When a particular switch is switched on, I want to set the integer to the corresponding integer 'variable' with a 1

So, if switch 2 with tag 2 is turned on, it puts a '1' in the corresponding int 'switch_2' as an integer.

I am getting a string with the right name via 'stringWithFormat' by appending the tag value but don't know how to write the 1 to the corresponding integer variable from it.

Any help would be greatly appreciated. Essentially, I want to write an integer to a 'variable' name with the same name as the generated string value.

Thanks

1
  • can you show the code related to it ? Commented Jan 7, 2016 at 13:59

1 Answer 1

0

You can use an array where each index represents your switch, so it would be like following:

int swtichArray[10] = {0}; // if you have 10 switches

While in your action where you handling action of multiple buttons, you could do that:

switchArray[tagOfSwitch] = 1; // if tags are staring from 0 onwards 9
Sign up to request clarification or add additional context in comments.

2 Comments

That worked perfectly. Many, many thanks!!!!!
Always glad to help :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.