Okay maybe i jus开发者_StackOverflow中文版t 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??
There's no format specifier in the NSLog statement that prints out the temp array.
you don't have a variable in the string that logs tempArray.
it should look like this:
NSLog([NSString stringwithformat:@"temp array: %@",tempArray]);
精彩评论