I am trying to save my data from a view that was loaded on applicationWillTerminate but am running into a few problems.
I have four views: inFinateViewController FirestViewController SecondViewController ThirdViewController
I am loading my views from like this (thanks to Mauricio Giraldo code) via the infinateViewController:
- (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];
}
And it starts up via:
- (void)viewDidLoad {
self.currentView = [[FirstViewController alloc]
initWithNibName:@"FirstView" bundle:nil];
[self.view addSubview:self.currentView.view];
[super viewDidLoad];
}
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.
In my SecondViewController I also have a method that has:
-(void) saveExitData
{
[pnames writeToFile:[self saveFilePath: @"gameArrayData.plist"] atomically:YES];
}
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:
- (void)applicationWillTerminate:(UIApplication *)application {
[secondViewController saveExitData];
}
My infinateViewsAppDelegate looks like this:
// InfiniteViewsAppDelegate.h
#import <UIKit/UIKit.h>
@class SecondViewController;
@class InfiniteViewsViewController;
@interface InfiniteViewsAppDelegate : NSObject <UIApplicationDelegate> {
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
and the .m File:
// 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
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?
Thanks to anyone who can shed some light on this. I have read books upon books and googled forever...but still no answer.
Geo...