How to pass a variable between multiple views / XIB

I read a few similar topics, but I seem to be unable to figure it out - sorry. I have a project with several views, including a ViewController, several “under” views, and a NavigationController. I would like to have an array accessible from any of the views, so that I can populate a TableView or TextField, etc. I would like the array to be modifiable from any view that can access it.

Now I have this in the xxAppDelegate.h file:

NSMutableArray *listOfHeadings;
@property (strong,nonatomic) NSMutableArray *listOfHeadings;

And in the xxAppDelegate.m file, I populate the array:

listOfHeadings = [[NSMutableArray alloc] init];
[listOfHeadings addObject:@"Heading 0"];
[listOfHeadings addObject:@"Heading 1"];

But I can not access the array from other .m files. How to do it right?

0
source share
3 answers

AppDelegate, :

AppDelegate *dPtr = (AppDelegate *)[[UIApplication sharedApplication] delegate];

:

[dPtr.your_array objectAtIndex:i];

Singleton .

0

xxAppDelegate, , :

#import "xxAppDelegate.h"
//...
NSMutableArray *array
= [(xxAppDelegate *)[[UIApplication sharedApplication] delegate] listOfHeadings];
+1

, / , . , , subview/controller, , ( , ) (, ).

- Singleton , .

+1

All Articles