I am currently using the following code in the AppDelegate to make a UIBarButtonItem act as a switch and adjusts a BOOL variable in the RootViewController Class:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
...
toggleSwitch = [[UIBarButtonItem alloc] initWithTitle:@"English" style:UIBarButtonItemStylePlain target:self action:@selector(togglePress:)];
...
}
And then the selector comes later in the AppDelegate:
-(IBAction) togglePress:(id)sender {
RootViewController *viewController;
if (viewController.searchEnglish) {
viewController.searchEnglish = NO;
toggleSwitch.title = @"English";
}
else {
viewController.searchEnglish = YES;
toggleSwitch.title = @"OtherLanguage";
}
}
I basically check to see if the BOOL from the RootViewController class is set to YES and if it is then set it to NO and change the title of the button to 'OtherLanguage,' otherwise do the opposite. However when I run the program and click the button,the BOOL variable and the title do not change, the application freezes and crashes. What am I doing wrong?