我的應用程序是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建議檢查您的歷史記錄是否爲零? –