title: Data Passing between VC : Objective C
body: <p>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).
  <a href="https://i.stack.imgur.com/HAQZk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HAQZk.png" alt="Image 1"></a></p>
  
  <p>When button "B" is pressed, in tab bar view controller below code gets executed :</p>
  
  <pre><code>- (void)centerButtonTapped:(id __unused)sender {
      BBVC *vc = [[BBVC alloc] init];
      UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
      [self presentViewController:nc animated:YES completion:nil];
  }
  </code></pre>
  
  <p>BBVC gets loaded as pop UP </p>
  
  <p><strong><em>My aim is I want to change the value of "UISwitch" based on "UIButton" action event.</em></strong></p>
  
  <p>Case 1 : Not On setting View<br>
  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 :</p>
  
  <pre><code>- (void)viewWillAppear:(BOOL)animated
  {
      NSLog(@"viewWillAppear");
      [super viewWillAppear:animated];
      NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
      [Switch setOn:[defaults boolForKey:@"EnableLIVE"] animated:YES];
  
  }
  </code></pre>
  
  <p>Case 2 :</p>
  
  <p>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.</p>
  
  <p><a href="https://i.stack.imgur.com/ttRRL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ttRRL.png" alt="Image 2"></a></p>
  
  <p>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.</p>
  
  <pre><code>-(void)viewDidDisappear:(BOOL)animated
  {
         NSLog(@"viewDidDisappear");
      NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
       [Switch setOn:[defaults boolForKey:@"EnableLIVE"] animated:YES];
  
  }
  </code></pre>
  
  <p>Attempt 2 :</p>
  
  <p>Use Delegate and Protocols :</p>
  
  <p>I have used delegate and protocols which is working fine but in this case address of UISwitch is nil. Please see below image</p>
  
  <p><a href="https://i.stack.imgur.com/af0Rr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/af0Rr.png" alt="image 3"></a></p>
  
  <p>Note : UISwitch is created programmatically. </p>
  
  <p>I am clueless here. Any kind of help is appreciated.
  Thank you.</p>