-1

I've connected a UISegmentedControl outlet. In my viewDidLoad() I check some stuff out to determine if I need to jump to the third index of the UISegmentedControl but I had no luck.

I made this:

self.mainSelector.isEnabledForSegmentAtIndex(2)

Of course it did't work. What should I do to jump automatically to the third segment?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
A. Sola
  • 107
  • 1
  • 12
  • Is `selectedSegmentIndex = 2` what your looking for? It sets the third segmented to the selected state. – paulvs Feb 21 '16 at 19:55
  • I think it worked. I did mainSelector.selectedSegmentIndex = 2, and it changes the tab but it doesn't load its content. Only change the selected tab but it doesn't go to that view. – A. Sola Feb 21 '16 at 20:25
  • Setting the selected segment programatically doesn't fire the segment's actions. – paulvs Feb 21 '16 at 20:35
  • So what should I do? I've instantiated the view controller I want to show but it's shown full screen. This viewController is a UIContentView so I need to be presented that way. – A. Sola Feb 21 '16 at 20:38
  • It's not clear to me what you're trying to do, and what is a `UIContentView`? – paulvs Feb 21 '16 at 20:42
  • UIContainerView excuse me! – A. Sola Feb 21 '16 at 20:45
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/104117/discussion-between-paulvs-and-a-sola). – paulvs Feb 21 '16 at 20:51

1 Answers1

1

The selected segment in a UISegmentedControl is determined by its selectedSegmentIndex.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I've made let vc : AnyObject! = self.storyboard!.instantiateViewControllerWithIdentifier("random") self.showViewController(vc as! UIViewController, sender: vc) but it shows the view controller not inside UISegmentControl but full screen just like a normal view – A. Sola Feb 21 '16 at 20:31
  • That isn't what you asked. If you have a different question, ask a different question. – matt Feb 21 '16 at 20:33