2013-06-05 41 views
0

我試圖讓我的應用程序保存,當我按下教程後按主頁按鈕http://mobileorchard.com/how-to-make-an-iphone-app-part-6-saving-data/ 我完成了教程(使用代碼我已經在工作,而不是製作一些新的教程),我有錯誤Q1,Q2是未申報(他們是我的文本框IB)xcode說我的界面生成器的文本框沒有聲明

- (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 
+0

向我們展示您的.h代碼,您是否在界面構建器中連接了q1和q2? – JSA986

+0

我剛剛發佈了我的.h howq連接我的q1和q2的界面生成器? –

+0

這就是你的appDeleagte的代碼,其中是你的.h和.m在MainControllerView.h中的代碼? – JSA986

回答

0

但是,在q1和q2文本字段是否被聲明?在哪個視圖控制器中,您是通過接口構建器還是通過代碼創建它們?那麼他們將如何在applicationDidEnterBackground方法中得到承認,在NSArray對象中,您將其添加到了哪個對象中?

就我所見,您正試圖從AppDelegateapplicationDidEnterBackground方法中的一些視圖控制器的文本字段文本中保存一些值。要做到這一點,你必須將文本保存在某些屬性的字符串中。指向視圖層次結構中的視圖控制器,並從該實例的那些屬性中獲取這些字符串。然後從那裏,你可以將它保存到數組中或者對它們進行任何其他程序。