Good morning,
what I try to achieve is to draw a graph inside a view whilst data are being added live in the VC through an Array.
So far I have a VC and a view with its own class. Inside the class, inside drawRect I generate random numbers and they appear on the screen as dots. So far, so good.
What I want to do is generate the numbers in the ViewController (or get them via an external source), save them in a mutableArray, retrieve them inside the class and use them for the graph.
I found a similar question here on SO, from 2 years ago so there is no point commenting on it. The question was : I have on FirstViewController an array with float value. I need to pass to my View this array
The recommended solution, that was marked as working was :
In your FirstViewController.h write
#include <UIKit/UIKit.h>
extern NSArray *yourArray;
And in your FirstViewController.m write
#import "FirstViewController.h"
@interface FirstViewController ()
@end
NSArray *yourArray;
Now you'll have to import the whole FirstViewController in your "MyView"-Class. Simply #import "FirstViewController.h" in MyView.m. After doing so, "yourArray" will be available in MyView.
I do exactly what it says, then I initialize my Array, put values in it, NSLog in VC to check all working fine and it does. When I try to retrieve one value in my view and NSLog it, it says the value in the array is (null). The code is so simple I almost have nothing to show:
In my VC.h
extern NSMutableArray *yourArray;
In my VC.m implementation
NSMutableArray *yourArray;
In my VC.m viewDidLoad
NSMutableArray *yourArray = [[NSMutableArray alloc] init];
[yourArray insertObject:@"Works" atIndex:0];
NSString *object = [yourArray objectAtIndex:0];
NSLog (@"the item in Array in VC is %@", object);
In my view.m
#import "GraphViewController.h"
And then I tried adding:
NSString *object = [yourArray objectAtIndex:0];
NSLog (@"the item in Array in View is %@", object);
in (void)awakeFromNib, in (id)initWithFrame:(CGRect)frame, in (void)updateValues and in (void)drawRect:(CGRect)rect
It doesn't work from anywhere I put it. I am at a complete loss.
Could somebody please point me in the right direction ?
Thanks,
=============================================