Method in RootViewController not Storing Array
Posted
by Antonio
on Stack Overflow
See other posts from Stack Overflow
or by Antonio
Published on 2010-06-14T18:12:22Z
Indexed on
2010/06/16
2:42 UTC
Read the original article
Hit count: 229
I have an array initialized in my RootViewController and a method that addsObjects to an array. I created a RootViewController object in my SecondViewController. The method runs (outputs a message) but it doesn't add anything to the array, and the array seems empty. Code is below, any suggestions?
RootViewController.h
#import "RootViewController.h"
#import "SecondViewController.h"
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
myArray2 = [[NSMutableArray alloc] init];
NSLog(@"View was loaded");
}
-(void)addToArray2{
NSLog(@"Array triggered from SecondViewController");
[myArray2 addObject:@"Test"];
[self showArray2];
}
-(void)showArray2{
NSLog(@"Array Count: %d", [myArray2 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 "RootViewController.h"
@implementation SecondViewController
-(IBAction)addToArray{
RootViewController *object = [[RootViewController alloc] init];
[object addToArray2];
}
-(IBAction)switchBack{
[self dismissModalViewControllerAnimated:YES];
}
EDIT*****
With Matt's code I got the following error:
" expected specifier-qualifier-list before 'RootViewController' "
© Stack Overflow or respective owner