title: Using variable value from another class Objective-c
body: <p>I know this has been posted many times but I cannot get it to work, there are no errors in my code (found by Xcode), but what I'm trying to do isn't working.</p>
  
  <p>1- Setup: I have 2 classes, <code>ViewController (UIViewController)</code> and <code>GraphView (UIView)</code></p>
  
  <p>2- What I am trying to do: I have a BOOL type variable <code>plotPressedVC</code> in ViewController that takes an initial value <code>NO</code>. 
  Once a button is pressed (this <code>IBAction</code> is located in the ViewController.m file) <code>plotPressedVC = YES</code>. From this, in my GraphView.m file I have an <code>if</code> statement whose condition is met if <code>pressed = YES</code>.</p>
  
  <p>3- My code:</p>
  
  <p><strong>ViewController.h</strong></p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface ViewController : UIViewController  {
      @public BOOL plotPressedVC;
  }
  
  - (IBAction)plot:(id)sender;
  
  @end
  </code></pre>
  
  <p><strong>ViewController.h</strong></p>
  
  <pre><code>#import "ViewController.h"
  #import "GraphView.h"
  
  @implementation ViewController
  
  - (void)viewDidLoad {
      [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
  
      plotPressedVC = YES;
  }
  
  - (IBAction)plot:(id)sender {
      plotPressedVC = YES;
  
      GraphView *plotPress = [[GraphView alloc] init];
      plotPress.plotPressed = plotPressedVC;
  }
  
  @end
  </code></pre>
  
  <p><strong>GraphView.h</strong></p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  
  @interface GraphView : UIView {
      BOOL plotPressed;
  }
  
  @property (nonatomic) BOOL plotPressed;
  
  @end
  </code></pre>
  
  <p><strong>GraphView.m</strong></p>
  
  <pre><code>#import "GraphView.h"
  #import "ViewController.h"
  
  @implementation GraphView
  
  - (void)drawLineGraphWithContext:(CGContextRef)ctx {
  
      if (plotPressed == YES) {
          NSLog(@"yep");    
      }
  
      // Other code that I want to be in if statement
  }
  
  @end
  </code></pre>
  
  <p>4- Question: What have I done wrong for the if statement's condition to not have been met when pushing the button <code>plot</code>? </p>
  
  <p><strong>EDIT</strong>: added <code>NSlog</code> at the end of the <code>plot</code> action, I am getting values 80, -64, -128...</p>
  
  <pre><code>- (IBAction)plot:(id)sender {
  
      plotPressedVC = YES;
  
      NSLog(@"%hhd",plotPressedVC);
  
      GraphView *plotPress = [[GraphView alloc] init];
      plotPress.plotPressed = plotPressedVC;
  
      NSLog(@"%hhd",plotPress);
  
  }
  </code></pre>
  
  <p>New Question: How come plotPress is receiving other numbers than 0 or 1?</p>