title: applicationWillTerminate with multiple views
body: <p>I am trying to save my data from a view that was loaded on applicationWillTerminate but am running into a few problems.</p>
  
  <p>I have four views:
  inFinateViewController
  FirestViewController
  SecondViewController
  ThirdViewController</p>
  
  <p>I am loading my views from like this (thanks to Mauricio Giraldo code) via the infinateViewController:</p>
  
  <pre><code>- (void) displayView:(int)intNewView {
  
  NSLog(@"%i", intNewView);   
  
  [self.currentView.view removeFromSuperview];
  [self.currentView release];
  switch (intNewView) {
      case 1:
          self.currentView = [[FirstViewController alloc] initWithNibName:@"FirstView" bundle:nil];
          break;
      case 2:
          self.currentView = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:nil];
          break;
      case 3:
          self.currentView = [[ThirdViewController alloc] initWithNibName:@"ThirdView" bundle:nil];
          break;
  }
  
  [self.view addSubview:self.currentView.view];
  
  CATransition *animation = [CATransition animation];
  [animation setDelegate:self];
  [animation setType:kCATransitionReveal]; 
  [animation setDuration:0.75];
  [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
  [[self.currentView.view layer] addAnimation:animation forKey:kCATransition];
  </code></pre>
  
  <p>}</p>
  
  <p>And it starts up via:</p>
  
  <pre><code>- (void)viewDidLoad {
  self.currentView = [[FirstViewController alloc]
                 initWithNibName:@"FirstView" bundle:nil];
  [self.view addSubview:self.currentView.view];
  [super viewDidLoad];
  }
  </code></pre>
  
  <p>In my SecondViewController, I have a NSMutableArray that on start, I initialize with numbers, scramble them, and then use.  My goal is to save these entries when the applicationWillTerminate is called.</p>
  
  <p>In my SecondViewController I also have a method that has:</p>
  
  <pre><code>-(void) saveExitData
  {
  [pnames writeToFile:[self saveFilePath: @"gameArrayData.plist"] atomically:YES];
  
   }
  </code></pre>
  
  <p>My problem is that the applicationWillTerminate is in the appDelegate and although I am calling it, it does not seem to run.  I attempted to step into it via debugger, but it only hits it and never jumps into it.  Code is:</p>
  
  <pre><code>- (void)applicationWillTerminate:(UIApplication *)application {
  [secondViewController saveExitData];
  
  } 
  </code></pre>
  
  <p>My infinateViewsAppDelegate looks like this:</p>
  
  <pre><code>//  InfiniteViewsAppDelegate.h
  #import &lt;UIKit/UIKit.h&gt;
  @class SecondViewController;
  @class InfiniteViewsViewController;
  
  @interface InfiniteViewsAppDelegate : NSObject &lt;UIApplicationDelegate&gt; {
  UIWindow *window;
  InfiniteViewsViewController *viewController;
  SecondViewController  *secondViewController;
  
  }
  
  @property (nonatomic, retain) IBOutlet UIWindow *window;
  @property (nonatomic, retain) IBOutlet InfiniteViewsViewController *viewController;
  @property (nonatomic, retain) IBOutlet SecondViewController *secondViewController;
  
  -(void) displayView:(int)intNewView;
  
  @end
  </code></pre>
  
  <p>and the .m File:</p>
  
  <pre><code>//  InfiniteViewsAppDelegate.m
  #import "SecondViewController.h"
  #import "InfiniteViewsAppDelegate.h"
  #import "InfiniteViewsViewController.h"
  
  @implementation InfiniteViewsAppDelegate
  
  @synthesize window;
  @synthesize viewController;
  @synthesize secondViewController;
  
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
  [window addSubview:viewController.view];
  
  [window makeKeyAndVisible];
  
  return YES;
   }
  
  - (void)displayView:(int)intNewView {
  [viewController displayView:intNewView];
  }
  
  - (void)dealloc {
  [viewController release];
  [window release];
  [super dealloc];
  }
  
  
  @end
  </code></pre>
  
  <p>So, I guess my question is, how would I be able to save this data?  Can the applicationWillTerminate be placed in my SecondViewController so I could write the data and save from there?  Or does applicationWillTerminate only exist in the appDelegate?</p>
  
  <p>Thanks to anyone who can shed some light on this.  I have read books upon books and googled forever...but still no answer.</p>
  
  <p>Geo...</p>