Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 649167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:54:49+00:00 2026-05-13T21:54:49+00:00

I am trying to save my data from a view that was loaded on

  • 0

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:54:50+00:00Added an answer on May 13, 2026 at 9:54 pm

    If your app delegate is set up correctly, applicationWillTerminate: should definitely be called. You should investigate this because if it isn’t, you have an error somewhere.

    It’s not necessary to solve your problem, though: besides applicationWillTerminate:, the UIApplication instance will also send out a notification named UIApplicationWillTerminateNotification on exit. You can have your view controllers observe this notification and then there is no need for your app delegate to maintain a reference to your view controllers.

    When a view controller is created, have it register for the notification:

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(applicationWillTerminateNotification:)
                                                 name:UIApplicationWillTerminateNotification
                                               object:[UIApplication sharedApplication]];
    

    The notification center will then call the selector you specified and you can save your stuff in that method:

    - (void)applicationWillTerminateNotification:(NSNotification *)notification {
        // save stuff ...
    }
    

    Don’t forget to unregister yourself when the view controller is deallocated:

    [[NSNotificationCenter defaultCenter] removeObserver:self 
                                                    name:UIApplicationWillTerminateNotification 
                                                  object:[UIApplication sharedApplication]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to save the returned data from HTTP request into a variable. The
I am trying to save data into the same table several times from the
I'm trying to save some data into an array but unfortunately all the data
I'm trying to save some data to core data from a different view and
I am trying to create & save images from data in an email from
I am trying to save some data for a android game, but I cant
I have a DataGridView that displays data from a MS Access database. I'm using
I am trying to save data via NSUserDefaults and view it on the tableView
I am trying to save few property into the plist when the user starts
I'm trying to save the content of a view into a PDF file.The code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.