SOffer[26229:c07] current Product: (
{
id = 20;
image = "img2.png";
name = "offer 2";
}
)
I have product which result the above when I print it through NSLog,, I need to print the these individually. Following code generate this
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } NSString *currentProductName; currentProductName = [productKeys objectAtIndex:indexPath.row]; currentProduct = [products objectForKey:[productKeys objectAtIndex:indexPath.row]]; NSLog(@"current Product: %@",currentProduct); //currentProductName = [currentProduct objectForKey:@"image"]; //currentProduct = [currentProduct ]; [[cell textLabel] setText:currentProductName]; return cell; }
currentProduct is declared as NSArray but when i try to print with objectForKey it say No visible interface for NSArray declares the selector ObjectForKey
objectForKey
i believe works withNSDictionary
only.NSArray
does not have key value pairs. UnlesscurrentProduct
holds the JSON file, then you gonna have to first get out the Array Object of the first Product and assign it to aNSDictionary
, where you can then use theobjectForKey
to get your image value – StevenobjectForKey
is receiving a value that is not expected. Separate your two calls into different lines and do aNSLog
to see if those are the values you expect – Steven