我的应用程序是SplitView类型,我使用UITableView
来显示网站的名称。在didSelectRowAtIndexPath
方法,我使用的代码行如下::将数据附加到NSDictionary
dateString = [formatter stringFromDate:[NSDate date]];
dict = [[NSDictionary alloc] init];
dict = [NSDictionary dictionaryWithObjectsAndKeys: urlString, dateString, nil];
[history addObject:dict];
NSLog(@"dateString: %@", dateString); //will let you know if it's nil or not
NSLog(@"urlString : %@", [dict objectForKey:dateString]);
NSString *docDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSLog(@"docDir is yoyo :: %@", docDir);
NSString *spaceFilePath = [docDir stringByAppendingPathComponent:@"space.txt"];
[history writeToFile:spaceFilePath atomically: TRUE];
我想要的网站访问非常久远的时间戳到NSDictionary
“字典”添加URL。我已经在viewDidLoad
方法中初始化格式化程序。 History是存储字典列表的数组。
我用下面的代码行viewDidLoad
方法:
formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
我要追加新址参观到已存在的文件space.txt名称。
但是,只有一个名称出现(上次访问的网站的网址)。如何将新访问的siteNames追加到我现有的文件space.txt中?我无法解决这个问题。
感谢和问候。
添加字典之后,打印历史记录并验证值?并且@Rajesh建议检查您的历史记录是否为零? –