Frenck
Frenck

Reputation: 6534

Parse the .plist items

When i'm trying to parse something strange happends.

I'm counting my items with

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);

And then:

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

    return [tableData count];
}

This works great but then in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

i tried

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;

But the output is:

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

)

And in my tablecell it also displays as

(
        Yeah,
        Trol,
       LOL,

    )

Upvotes: 1

Views: 106

Answers (1)

user529758
user529758

Reputation:

So you got

( yeah, trol, lol )

...in one cell, right? Now, that's natural. If you had read NSLog's or NSString's documentation, you would have found out that the %@ format specifier calls an object's description method - which, in turn, for an NSArray object, is a pretty parenthesized, comma separated list of... again, the descriptions of its objects.

What you probably want is

cell.Data.text = [dataFromPlist objectAtIndex:indexPath.row];

Upvotes: 1

Related Questions