FirstViewController.h:
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController
{
NSArray *listData;
}
-(IBAction) GoToInsert: (id) sender;
@property (nonatomic, retain) NSArray *listData;
@end
FirstViewController.m:
-(IBAction) upisiRezultat:(id)sender
{
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName: nil bundle: nil];
[self presentModalViewController: secondView animated: NO];
[secondView release];
}
- (void)viewDidLoad
{NSArray *array = [[NSArray alloc] initWithObjects:@"236", @"46",
@"147", @"8", @"56", @"69", @"114", @"2",
@"96", @"518", @"2", @"54", @"236", nil];
self.listData = array;
[array release];
[super viewDidLoad];
}
SecondViewontroller.h
@interface SecondViewController : UIViewController {
}
-(IBAction) insert;
@end
SecondViewontroller.m
-(IBAction) insert
{
/* Here should be the code to insert some number in listData from FirstViewController */
}
So when the app loads it loads FirstViewController.xib and shows the listData array on screen, when I click button “Go to Insert” another view is loaded (SecondViewController.xib) with button “Insert” which should add some number into the array and display the new array on the first view.
How to do that?
You can access the parent view controller with
self.parentViewController. Therefore something along these lines (meaning I haven’t tested this — you should) should work:However, since you want to add objects to
listArray, it would be more natural to use anNSMutableArrayinstead. Also, you are currently addingNSStrings to the array, when it looks more like you want to haveNSNumberobjects.