I am trying to write an application that has a NSMutableArray that needs to be accessed and modified in a different View.
The MainViewController displays a table that gets the information from an NSMutableArray. The SecondaryViewController is used to addObjects into the array.
How do I go about this without declaring it as a global variable?
EDIT:
This is what I have so far:
(MainView .m)
#import "arrayTestViewController.h"
@implementation arrayTestViewController
-(void)viewDidLoad{
myArray = [[NSMutableArray alloc] init];
}
-(IBAction)showArray{
NSLog(@"Array Count: %d",[myArray count]);
}
-(IBAction)addToArray{
[myArray addObject:@"Test"];
[myArray addObject:@"Test2"];
NSLog(@"Array Count: %d", [myArray count]);
}
-(IBAction)switchViews{
SecondViewController *screen = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:screen animated:YES];
[screen release];
}
(SecondViewController .m)
#import "SecondViewController.h"
#import "arrayTestViewController.h"
@implementation SecondViewController
-(IBAction)addToArray{
// Trying to make a method add to myArray in the Main, but not sure of the syntax
// I'm guessing localizing another array and pointing to the original?
}
-(IBAction)switchBack{
[self dismissModalViewControllerAnimated:YES];
}