【发布时间】:2012-06-22 09:14:28
【问题描述】:
我的应用属于 SplitView 类型,我使用 UITableView 显示网站名称。在didSelectRowAtIndexPath 方法中,我使用以下代码行::
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“dict”中。我已经在viewDidLoad 方法中初始化了格式化程序。 History 是一个存储字典列表的数组。
我在viewDidLoad 方法中使用了以下代码行:
formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
我想将访问的新站点的名称附加到已经存在的文件space.txt中。
但是,仅显示一个名称(最后访问的站点的 url)。如何将新访问的站点名称附加到我已经存在的文件 space.txt 中?我无法解决这个问题。
感谢和问候。
【问题讨论】:
-
添加 dict 后,打印历史记录并验证值?正如@Rajesh 建议的那样检查您的历史记录是否为零?
标签: iphone objective-c ios xcode ipad