0

I have a main view where I initialize severals arrays and released them in viewDidUnload. So when I change to other view where I have the instruccions and I come back to the main view all the array are nil again.

What I what to do is: when the app is lunched, the arrays are initialized, y use them, I could go to others views and when come back to the main view that the arrays keep the values, and only when the app is close then release all the arrays.

How do I have to do it?

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285

2 Answers2

0

Just release them in -dealloc and initialize them in viewDidLoad. That way theyre only released or nullified when the view shuts down and when it is reloaded, they are reinitialized.

Hope this helps.

Jamie
  • 5,090
  • 28
  • 26
0

You can use different approaches for your problem. I can tell you some ways.

  • You can write methods for view initialization which will take NSArray as parameter. Like:

    - (id)initWithArray:(NSArray *)myArray {
        [super init];
        //here you can store an NSArray inside this ViewController in @property. For ex:
        currentArray = myArray;
        return self;
    }
    
  • You can use global storage like CoreData and use NSManagedObject class to define instances for necessary object in every view.

  • You can use delegate approach. For example you can delegate methods from second view in first view.

Community
  • 1
  • 1
kokoko
  • 2,705
  • 3
  • 17
  • 28
  • Thanks a lot but as I told you I am a really beginner, where do I have to insert the code? I have only a header and an implementation: ViewController.h and ViewController.m here is the initilization: - (void)viewDidLoad { //iniciliza la tabla tableViewData = [[NSMutableArray alloc] initWithObjects:nil]; tableViewDataDetail = [[NSMutableArray alloc] initWithObjects:nil]; [super viewDidLoad]; } So, each time I go to the other view and come back I loose the data I entered. How do I have to use the initWithArray? and again sorry for being so stupid. – user1243660 Mar 02 '12 at 11:10