-2

I'm parsing something right now and i want to display it in a cell i', using this code for my tableview but i also want it without Tablview

    NSString *const JsonDataUrl = [NSString stringWithFormat: @"%@", appdownloadurl];
    NSString *jsonString = [NSString 
                            stringWithContentsOfURL:[NSURL URLWithString:JsonDataUrl] 
                            encoding:NSUTF8StringEncoding
                            error:nil];

    SBJSON *parser = [[SBJSON alloc] init];

    NSDictionary *results = [parser objectWithString:jsonString error:nil];

    parser = nil;

    [self setTableData:[results objectForKey:@"resultCount"]]; 

This works great but when i place this line in viewdidload

NSDictionary *item = [tableData objectAtIndex:[indexPath row]];

NSLog(@"Apple: %@", [item objectForKey:@"price"]);

And error shows up on this line;

NSDictionary *item = [tableData objectAtIndex:[indexPath row]];

//Unknown recieiver 'indexPath'l did you mean NSIndexPath?

does anyone know how to fix this?

4

2 回答 2

0

Do you declare any variable called indexPath in your viewDidLoad method? You can't just use the indexPath from your table view methods in viewDidLoad arbitrarily.

于 2012-05-05T20:21:16.363 回答
0

NSDictionary *item = [tableData objectAtIndex:[indexPath row]]; suggests you are trying to load from an NSArray, you probably want to try something like:

NSDictionary *item = [tableData objectForKey:@"Some Key"];
于 2012-05-05T20:21:20.233 回答