Possible Duplicate:
Passing Data between View Controllers
I have on FirstViewController an array with float value. I need to pass to my View this array when the user clicks on a button. This button will call the View and draw the points informed.
Possible Duplicate:
Passing Data between View Controllers
I have on FirstViewController an array with float value. I need to pass to my View this array when the user clicks on a button. This button will call the View and draw the points informed.
1. 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.
Or, 2., you could write something like this into MyView.h:
- (void)drawRect(NSArray *)yourArray;
and in your FirstViewController.m, simply pass the data: (don't forget to #include MyView.h)
MyView *myView = [[MyView alloc]init];
[myView drawRect:yourArray]; //You'll have to pass "yourArray", to the function in MyView, which is going to be called
Or, 3., if you're using storyboard, you could
- (IBAction)pushedButton(UIButton *)sender {
[self performSegueWithIdentifier:@"pushButton" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"pushButton"] {
MyView *destinationViewController = segue.destinationViewController;
destinationViewController.yourArray = yourArray; // you'll have to define yourArray in the .h File
}
}