Search code examples
iosbooleanmodalviewcontrolleruiswitch

iOS - Setting UISwitch on/off state on a Modal View Controller


I'm having problems setting the state of a UISwitch from a BOOL. This is probably simple, so if anybody could help I'd really appreciate it. Here is my code which doesn't work, but it might make it more clear.

 RoutingController *routingController = [[RoutingController alloc] initWithNibName:@"RoutingController" bundle:nil];

routingController.routingDelegate = self;

if (audioController->oscOneLFObool == YES) {
    routingController.oscOneLFOOneSwitch.on = YES;
} else {
    routingController.oscOneLFOOneSwitch.on = NO;
}


routingController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

[self presentModalViewController:routingController animated:YES];

Solution

  • RoutingController's view not load,so oscOneLFOOneSwitch is nil.

    view load in [self presentModalViewController:routingController animated:YES]