iphone nsarray问题?

时间:2010-05-18 01:29:11

标签: iphone objective-c nsarray nslog

好吧也许我只需要另外一套眼睛,但我的一个视图控制器中有以下几行代码。它从文件中获取一些数据,并使用“\ 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

这是数组中正确的字符串数

所以我很难过。我在不同的视图控制器中有相同的几行代码,它完美地工作。什么更疯狂是最后一个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"
    );

\

我错过了一些非常明显的东西吗?

2 个答案:

答案 0 :(得分:2)

NSLog语句中没有打印出临时数组的格式说明符。

答案 1 :(得分:1)

在记录tempArray的字符串中没有变量。

它应该是这样的:

NSLog([NSString stringwithformat:@"temp array: %@",tempArray]);