MainControllerView -> ProtectionViewController as childview -> BackupViewController (as subview) -> UISwitch (as subview)

If you put a UISwitch on ProtectionViewController, it works. Remove the target for the switch, clicked as innocent.

PS Target is present :) Debazhil, to him, even the transition is not carried out.

CGRect switchRect = CGRectMake(self.view.frame.size.width - 65, 110, 25, 10); self.switchButton = [[UISwitch alloc] initWithFrame:switchRect]; self.switchButton.on = NO; [self.switchButton addTarget:self action:@selector(switchToggled) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:self.switchButton]; 
  • Is the selector appropriate? - (void) switchToggled {} ?? - iFreeman
  • Yes. Announced the controller through the property - it worked. - iSerg

1 answer 1

ViewController 's have no subview at all, controller.view . And the rest is too messy written and there is not enough data, what is your switch doing there? After all, something is crumbling inside its target, so bring this target or put break points and find out what after it crashes. While it seems like "I have a car, it does not go, why?"

Update

You wrote it after my commentary, but not the point. In general, if it falls on a call to a target, then there is no such selector - either you don’t pull that class (it’s very similar, if you use exactly the same on ProtectionViewController , then it’s there, not BackupViewController ), or not signature (say, -(void) switchToggled:(id) sender together -(void) switchToggled )

  • I wrote that the target does not even reach. If the problem were in the target method (inside), the question would have been different. - iSerg
  • Updated the answer - aknew
  • Most likely I accidentally pissed off something with the controllers. Instead of the usual creation of the controller, I made it as a property. It all worked. - iSerg