使用NSString的结果设置整数'变量'

时间:2016-01-07 13:55:52

标签: ios nested integer uiswitch

我正在使用单个动作通过向其发送标记值来处理10个UISwitch。因此,我在启动时会初始化一些整数;

int switch_1 = 0; int switch_2 = 0;等

当一个特定的开关打开时,我想将整数设置为相应的整数'变量',其中1

因此,如果打开带有标记2的开关2,它会将相应的int'witch_2'中的'1'作为整数。

我通过'stringWithFormat'获取一个正确名称的字符串,方法是附加标记值,但不知道如何将1写入相应的整数变量。

非常感谢任何帮助。本质上,我想将一个整数写入一个'变量'名称,其名称与生成的字符串值相同。

由于

1 个答案:

答案 0 :(得分:0)

您可以使用每个索引代表您的开关的数组,因此它将如下所示:

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

在您处理多个按钮操作的操作中,您可以这样做:

switchArray[tagOfSwitch] = 1; // if tags are staring from 0 onwards 9