iphone nsarray问题?

标签 iphone objective-c nsarray nslog

好吧,也许我只需要另一组眼睛来了解这个,但我的一个 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/

相关文章:

iphone - 在 UITableView 中垂直居中 UITableViewCell

iphone - 在 objective-c 中对负数和正数进行排序

ios - 如何在填充UIImageViews的NSArray中搜索某个图像属性?

iphone - 在 _one_ ASIHTTPRequest 中流式传输多个文件

iphone - 获取 UIView 类型

iphone - 在 iOS 中检测 iTunes Store 的国家

iphone - UIApplicationDidFinishLaunchingNotification的使用

ios - If 带日期的语句

iphone - Objective-c 如何在 GMT 时区获取没有时间分量的日期?

objective-c - enumerateObjectsUsingBlock : used for? 的 BOOL *stop 参数是什么