Reputation: 303
How can I set the default value of my UISwitch object to Off? I am probably missing something obvious?
Upvotes: 5
Views: 9578
Reputation: 4553
As mmccomb and Bruno Koga mentioned, this can be done programmatically. In this case, though--assuming that your UISwitch is getting unpacked from a nib--it may be more convenient to simply configure your UISwitch in Interface Builder.
To do this, open the xib that your switch is in, select your switch and open the Attributes Inspector (†) and within the "Switch" section, change the value of "State" from "On" to "Off":
† To open the Attributes inspector, first depress the right-end item ("Utilities") in the "View" segmented control at the far right of Xcode's toolbar
Once the Utilities Area appears with the Inspector Pane above the Library Pane, and select the Attributes Inspector item from the Inspector selector bar
All of this terminology comes from this image from Apple's Xcode documentation.
Upvotes: 16
Reputation: 3874
Assuming tha you have a reference for your UISwitch
, you could simply override the -viewDidLoad
method on your controller:
- (void)viewDidLoad
{
[super viewDidLoad];
[yourSwitch setOn:NO animated:NO];
}
Upvotes: 3
Reputation: 13807
Use the setOn:animated: method...
- (void)setOn:(BOOL)on animated:(BOOL)animated
e.g.
[someSwitch setOn:NO animated:YES];
Upvotes: 2