从UISegmentedControl获取字符串值


Answers:



30
[segmentedControl titleForSegmentAtIndex:int];

对于当前选择的索引

[segmentedControl titleForSegmentAtIndex:[segmentedControl selectedSegmentIndex]];

5

斯威夫特3:

segmentedControl.titleForSegment(at: segmentedControl.selectedSegmentIndex)

想知道这是为什么电话给我extra argument 'at' in call的错误中迅速3和Xcode 8.3
Umair

3

由于这是Google的第一个结果,因此我们现在处在快速时代:

迅速:

seg_ctrl.titleForSegmentAtIndex( seg_ctrl.selectedSegmentIndex)

0
@IBAction func segmentedControlAction(sender: AnyObject) {
    if(segementControl.selectedSegmentIndex == 0)
    {
        print(segementControl.titleForSegmentAtIndex(0))

    }
    else if(segementControl.selectedSegmentIndex == 1)
    {
         print(segementControl.titleForSegmentAtIndex(1))
    }
 }
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.