I am newbie working on objective C. I am facing one problem .
I have tab bar controller containing three view controllers out of which I am concerned about only two VCs named "Setting" and "BBVC" . "BBVC" has a UIButton and "Setting" has a UISwitch (Please see below image).
When button "B" is pressed, in tab bar view controller below code gets executed :
- (void)centerButtonTapped:(id __unused)sender {
BBVC *vc = [[BBVC alloc] init];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:nc animated:YES completion:nil];
}
BBVC gets loaded as pop UP
My aim is I want to change the value of "UISwitch" based on "UIButton" action event.
Case 1 : Not On setting View
In this case after pressing the UIButton, when I am on
"Setting" VC, the aim can be achieved by using viewWillappear and UserDefault as shown below :
- (void)viewWillAppear:(BOOL)animated
{
NSLog(@"viewWillAppear");
[super viewWillAppear:animated];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[Switch setOn:[defaults boolForKey:@"EnableLIVE"] animated:YES];
}
Case 2 :
In this case I am already on "Settings" VC (i.e. setting view is already loaded) and when button "B" from tab bar is pressed, it gets loaded as a pop up as shown in below image. I am trying to achieve my aim but its not working.
Attempt 1 : In Setting VC, I updated the code in "viewDidAppear" method but while debugging I got to know after closing BBVC, method "viewDidAppear" is not getting called.
-(void)viewDidDisappear:(BOOL)animated
{
NSLog(@"viewDidDisappear");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[Switch setOn:[defaults boolForKey:@"EnableLIVE"] animated:YES];
}
Attempt 2 :
Use Delegate and Protocols :
I have used delegate and protocols which is working fine but in this case address of UISwitch is nil. Please see below image
Note : UISwitch is created programmatically.
I am clueless here. Any kind of help is appreciated. Thank you.