1

I am trying to send a BOOL value from ViewController A to ViewController B. On ViewController A, dashboard.skip shows YES, but on ViewController B, self.skip shows NO.

- (IBAction)skipToDashboard:(UIButton *)sender {
    ViewController B *vc=[[ViewController B alloc]init];
    vc.presentButtonTag=sender.tag;
    self.fromSkip=YES;
    vc.skip=self.fromSkip;
}

In ViewController B:

@property (nonatomic,assign) BOOL skip;
Artem Novichkov
  • 2,356
  • 2
  • 24
  • 34
TestShroff
  • 87
  • 9

2 Answers2

0

Try to define BOOL property and set value either true or false.

For Ex: Appdelegate declare property and then use

@property (nonatomic) BOOL fromSkip;
Himanshu Patel
  • 1,015
  • 8
  • 26
0

There are 2 ways to pass your data from First screen to 2nd screen.

1st Way:

You can pass your data by creating VC object and assign value in it and push to next screen like below example.

Code :

//Initilize view controller from storyboard id.
ViewController *objViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];

//Assign value
objViewController.presentButtonTag=sender.tag;
self.fromSkip=YES;
objViewController.skip=self.fromSkip;

//Push view
[self.navigationController pushViewController:objViewController animated:YES];

2nd Way:

By Storyboard you can set segue action on button and in prepare segue method you need to pass your data like this.

Code:

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    if ([segue.identifier isEqualToString:@"ViewController"]) {
        ViewController *objViewController = (ViewController*)segue.destinationViewController;
        objViewController.selectedTag = ((UIButton*) sender).tag;
       //Assign value
      objViewController.presentButtonTag=sender.tag;
      self.fromSkip=YES;
      objViewController.skip=self.fromSkip;
    }
}

Now you can check your scenario in both condition I think you are pushing to next screen by storyboard so use 2nd Way.

Let me know if you need more help.

CodeChanger
  • 7,953
  • 5
  • 49
  • 80