我试图在plist文件中存储一些stings文件,保存过程正常,但应根据特定日期保存这些备注,例如我在2月2日输入备注那么我需要在2月5日输入另一张纸条,当我在这些日期间移动时,我的笔记应该显示在这些日期。如果你能帮助我,我将不胜感激。将文本保存到plist文件中并显示具体日期
这里是我的代码:
//Save Setting ///////////////////
- (NSString *) saveFilePath
{
NSArray *pathArray =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDate *date = [NSDate date];
return [[pathArray objectAtIndex:0] stringByAppendingPathComponent:@"note.plist"];
}
- (void)applicationWillTerminate:(UIApplication *)application
{
NSArray *values = [[NSArray alloc] initWithObjects:saveTextToday.text ,nil];
[values writeToFile:[self saveFilePath] atomically:YES];
[values release];
}
- (void)viewDidLoad
{
////Save Setting /////////////////////////////////////////////////
NSString *myPath = [self saveFilePath];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:myPath];
if (fileExists)
{
NSArray *values = [[NSArray alloc] initWithContentsOfFile:myPath];
saveTextToday.text = [values objectAtIndex:0];
[values release];
}
// notification
UIApplication *myApp = [UIApplication sharedApplication];
// add yourself to the dispatch table
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillTerminate:)
name:UIApplicationWillTerminateNotification
object:myApp];
}
实际上,'NSArray'的'writeToFile:atomically:'方法_will_会导致plist。 – omz 2012-02-02 19:17:34
@omz - 谢谢,你说得对,我会更新我的答案。我的意思是说,他的结构(即使它是一个plist)会在该日期和该日期的数据之间有任何关联。请注意,他的“date”变量甚至没有在saveFilePath方法中使用,也没有在该数组内使用任何NSDate。 – Rayfleck 2012-02-02 19:26:03
你会回顾我的问题吗? – 2012-02-02 22:15:15