Jayson Ong Jayson Ong - 2 months ago 5
iOS Question

Equivalent of UISegmentedControl selectedSegmentIndex in UISwtich- Objective C

I'm trying to convert a UISegmentedControl to a UISwitch. I was successful on checking the state of the switch.

And then I saw this line of code:

self.mobile3GSegment.selectedSegmentIndex = [mConfigurationService getBoolWithKey:NETWORK_USE_3G];

I tried to guess on how UISwitch do it. So...

self.mobile3GSwitch.state = [mConfigurationService getBoolWithKey:NETWORK_USE_3G];

and then I get this error:

Property 'selectedSegmentIndex' not found on object of type UISwitch

I know that UISwitch is not a segment and returns YES or NO. The error is not the focus here. What I'm trying to understand is how can I convert the segment line of code to make it work for UISwitch.

I'm pretty much lost right now. What is the proper way to do this?


You have to use a simple function setOn (Assuming your method for returning bool is correct).

[_mobile3GSwitch setOn:[mConfigurationService getBoolWithKey:NETWORK_USE_3G] animated:NO];