Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 分段控件给出一个数值_Ios_Objective C_Uisegmentedcontrol - Fatal编程技术网

Ios 分段控件给出一个数值

Ios 分段控件给出一个数值,ios,objective-c,uisegmentedcontrol,Ios,Objective C,Uisegmentedcontrol,我有一个分段控件,当用户选择第一段时,我希望它传递数字0、第二段1和第三段2。所以我以后可以这样做: NSString *submitFormJS = [NSString stringWithFormat:@"document.getElementById('usertype').value='**%@**';", **segment**]; 其中段等于数字:0、1或2 UISegmentedControl有一个名为selectedSegmentIndex的属性,您可能会发现该属性对此很

我有一个分段控件,当用户选择第一段时,我希望它传递数字0、第二段1和第三段2。所以我以后可以这样做:

NSString *submitFormJS = [NSString   
stringWithFormat:@"document.getElementById('usertype').value='**%@**';", **segment**];

其中段等于数字:0、1或2

UISegmentedControl
有一个名为
selectedSegmentIndex
的属性,您可能会发现该属性对此很有用。

我已经使用了该属性,但我无法将selectedSegmentIndex放入字符串中。您需要在格式字符串中使用整数类型(例如,
%ld
),而不是
%@
。这很有效!我只需要添加:(long)self.segment.selectedSegmentIndex并切换到%ld。非常感谢你!只需使用
%d
,您就不再需要
(长)
演员阵容了。它是一个
NSInteger
,因此您也可以使用
%i