Search code examples
objective-ciphonexcode7uiswitch

How to set my UISwitch state as default to "ON" in my application?


I am new to iOS development and I have a UISwitch in my application . But i wish that when my application is installed newly that UISwitch must be in "On" state. How to achieve this??


Solution

  • Make an IBOutlet of your switch

    In your interface it will appear like:

    @property (nonatomic, weak) IBOutlet *mySwitch;
    

    set its state in viewWillAppear. - (void)viewWillAppear:(BOOL)animated method will be like this

    - (void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
    
        [mySwitch setOn:YES animated:YES];
    
    }