1

当我试图解析一些奇怪的事情时。

我在数我的物品

NSString *bundlePathofPlist = [[NSBundle mainBundle]pathForResource:@"Mything" ofType:@"plist"];

     NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:bundlePathofPlist];

        NSArray *dataFromPlist = [dict valueForKey:@"some"];

      NSMutableArray *data = [NSMutableArray array];
    for(int i =0;i<[dataFromPlist count];i++)
    {
        //NSLog(@"%@",[dataFromPlist objectAtIndex:i]);
        [data addObject:[NSNumber numberWithInt:[dataFromPlist count]]];
    }
    [self setTableData:data];

        NSLog(@"%@", tableData);

进而:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [tableData count];
}

这很好用,但随后在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

我试过

NSString *bundlePathofPlist = [[NSBundle mainBundle]pathForResource:@"Mything" ofType:@"plist"];

NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:bundlePathofPlist];

NSArray *dataFromPlist = [dict valueForKey:@"some"];


NSLog(@"%@", dataFromPlist);

cell.Data.text = [NSString stringWithFormat:@"%@", dataFromPlist];

return cell;

但输出是:

2012-08-13 23:08:48.130 [30278:707] (
    Yeah,
    Trol,
   LOL,

)

在我的表格单元中它也显示为

(
        Yeah,
        Trol,
       LOL,

    )
4

1 回答 1

1

所以你得到了

( yeah, trol, lol )

……在一个牢房里,对吧?现在,这很自然。如果您阅读过文档NSLog'sNSString's文档,您会发现%@格式说明符调用对象的描述方法——反过来,对于一个NSArray对象,它是一个漂亮的括号、逗号分隔的列表......再次,它的对象的描述.

你可能想要的是

cell.Data.text = [dataFromPlist objectAtIndex:indexPath.row];
于 2012-08-13T21:27:28.750 回答