0

当我按照教程http://mobileorchard.com/how-to-make-an-iphone-app-part-6-saving-data/点击主页按钮时,我正在尝试保存我的应用程序 我完成了教程(使用我已经在编写的代码,而不是为教程制作新东西)并且我有错误 q1,q2 未声明(它们是我在 IB 中的文本框)

- (void)applicationDidEnterBackground:(UIApplication *)application
{
//TEST 
NSArray *values = [[NSArray alloc] initWithObjects:q1.text,q2.text,nil];
[values writeToFile:[self saveFilePath] atomically:YES];
[values release];
//TEST
}

这是我的 .h 视图:

#import "Spalsh_XcodeAppDelegate.h"
#import "MainControllerView.h"

@implementation Spalsh_XcodeAppDelegate
@synthesize window=_window;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions (NSDictionary *)launchOptions
{
   MainControllerView *mainController = [[MainControllerView alloc] init];

[_window addSubview:mainController.view];

// Override point for customization after application launch.
[self.window makeKeyAndVisible];
return YES;}

- (void)applicationWillResignActive:(UIApplication *)application
{
/*
 Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
 Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
 */
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
//TEST 
NSArray *values = [[NSArray alloc] initWithObjects:q1.text,q2.text,nil];
[values writeToFile:[self saveFilePath] atomically:YES];
[values release];
//TEST
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
/*
 Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
 */
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
/*
 Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
 */
}

- (void)applicationWillTerminate:(UIApplication *)application
{
/*
 Called when the application is about to terminate.
 Save data if appropriate.
 See also applicationDidEnterBackground:.
 */
}

- (void)dealloc
{
[_window release];
[super dealloc];
}

@end
4

1 回答 1

0

但是在哪里声明了 q1 和 q2 文本字段?在哪个视图控制器中,您是通过界面构建​​器还是通过代码创建它们。以及如何在您将它们添加到对象的方法applicationDidEnterBackground中确认它们?NSArray

据我所知,您正试图从AppDelegate'applicationDidEnterBackground方法中的某些视图控制器的文本字段文本中保存一些值。为此,您必须将文本保存在某个属性中的字符串中。指向视图层次结构中的视图控制器,并从该实例的这些属性中获取这些字符串。然后从那里,您将能够将其保存到阵列或对它们进行任何其他处理。

于 2013-06-05T18:28:56.580 回答