I have two view controllers and nibs. I populated one view controller with a toggle switch and declared this in its header file:
@public UISwitch *toggleSwitch;
and exposed it as a property like this:
@property (nonatomic,retain) IBOutlet UISwitch *toggleSwitch;
I also connected the switch with toggleSwitch outlet. Then I used this switch in my other view controller like this :
theViewControllerWhereIDeclaredTheSwitch.toggleSwitch.on = YES;
Though everything worked fine with the switch being ON by default but when I switched off the switch it threw an exception: “Thread 1: signal SIGABRT” in the main.m file. I get this error quite often while working with Xcode, this error is a real pain in my ass. Please help.
You should not share UI elements over multiple
UIViewControllers.A better approach would be to share a
BOOLor even encapsulate the state in your own object inheriting fromNSObjectand pass that between the 2UIViewControllers.