iphone nsarray 有问题吗?
好吧,也许我只是需要另一双眼睛来关注这一点,但我的一个视图控制器中有以下几行代码。它从文件中获取一些数据,并使用“\n”作为分隔符将其填充到数组中。然后,我使用该数组创建一个 NSDictionary,用于填充表格视图。这很简单。然而它不起作用。这是代码:
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);
因此在日志中,数据字符串是正确的,因此它正确地从文件中提取数据。但是对于 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
这是数组中正确的字符串数量
所以我被难住了。我在不同的视图控制器中有完全相同的几行代码,并且它工作得很好。更疯狂的是最后一个 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"
);
\
我错过了一些非常明显的东西吗?
Okay maybe i just need another set of eyes on this, but I have the following lines of code in one of my view controllers. It takes some data from a file, and populates it into an array using "\n" as a separator. I then use that array to make an NSDictionary, which is used to populate a tableview. It's very simple. However it isnt working. Here's the code:
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);
so in the log, datastring is correct, so it's correctly pulling the data from a file. however for tempArray, i get:
2010-05-17 19:15:55.825 MyApp[7309:207] temp array:
for the tempArray count i get:
2010-05-17 19:15:55.826 myApp[7309:207] 5
which is the correct number of strings in the array
So i'm stumped. I have the EXACT same few lines of code in a different view controller and it works perfectly. Whats crazier is the last NSLog, that shows the final NSDictionary (names) displays this, which looks correct:
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"
);
\
am i missing something really obvious??
NSLog 语句中没有打印临时数组的格式说明符。
There's no format specifier in the NSLog statement that prints out the temp array.