0
#import <UIKit/UIKit.h>
@interface SavingDataViewController : UIViewController {
UITextField *field1;
}
@property (nonatomic , retain) IBOutlet UITextField *field1;
-(NSString *) pathOfFile;
-(void) applicationWillTerminate:(NSNotification *) notification;
@end
@implementation SavingDataViewController
@synthesize field1;
-(NSString *) pathOfFile
{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *doucumentFolder = [path objectAtIndex:0];
return [doucumentFolder stringByAppendingFormat:@"myFile.plist"];
}
-(void) applicationWillTerminate:(NSNotification *) notification
{
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:field1.text];
[array writeToFile:[self pathOfFile] atomically:YES];
[array release];
}
- (void)viewDidLoad
{
NSString *filePath = [self pathOfFile];
if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
field1.text = [array objectAtIndex:0];
[array release];
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:app];
[super viewDidLoad];
}
我想節省的plist文件中的數據與此代碼,但是當我重新啓動程序,我在這行的問題: INT retVal的= UIApplicationMain(ARGC,ARGV ,零,零);有錯誤:程序收到信號如何在plist文件數據保存在可可觸摸
什麼我的問題呢?