好吧,也许我只需要另一组眼睛来了解这个,但我的一个 View Controller 中有以下几行代码。它从文件中获取一些数据,并使用“\n”作为分隔符将其填充到一个数组中。然后我使用该数组创建一个 NSDictionary,用于填充 TableView 。这很简单。但是它不起作用。这是代码:
NSString *dataString = [NSString stringWithContentsOfFile:checklistPath encoding: NSUTF8StringEncoding error:NULL];
if ([dataString hasPrefix:@"\n"]) {
dataString = [dataString substringFromIndex:1];
}
NSArray *tempArray = [dataString componentsSeparatedByString:@"\n"];
NSLog(@"datastring:%@",dataString);
NSLog(@"temp array:",tempArray);
NSLog(@"%i",[tempArray count]);
NSDictionary *temporaryDictionary = [NSDictionary dictionaryWithObject: tempArray forKey:@"User Generated Checklist"];
self.names = temporaryDictionary;
NSLog(@"names:%@",names);
所以在日志中,datastring 是正确的,所以它正确地从文件中提取数据。但是对于 tempArray,我得到:
2010-05-17 19:15:55.825 MyApp[7309:207] temp array:
对于我得到的 tempArray 计数:
2010-05-17 19:15:55.826 myApp[7309:207] 5
这是数组中正确的字符串数
所以我很难过。我在不同的 View Controller 中有完全相同的几行代码,它工作得很好。最疯狂的是最后一个 NSLog,它显示了最终的 NSDictionary(名称)显示了这个,看起来是正确的:
2010-05-17 19:15:55.827 FS Companion[7309:207] names:{
"User Generated Checklist" = (
"System|||ACTION",
"System|||ACTION",
"System|||ACTION",
"System|||ACTION",
"System|||ACTION"
);
\
我是否遗漏了一些非常明显的东西??
最佳答案
打印临时数组的 NSLog 语句中没有格式说明符。
关于iphone nsarray问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2854063/