tags:

views:

25

answers:

1

I have dictionary with 5 keys and corresponding value. How I can set the value in cell of UITable when I dont know key?

d=[[NSDictionary alloc] initWithObjectsAndKeys:@"Air Bus",@"ab", @"Boeing 787 ",@"787",@"Some Plane", @"sp",nil];

+2  A: 

Hi,

You can show a list of the keys in the dictionary like this :

for (id key in [myDictionary allKeys])
  NSLog(@"Key : %@ => value : %@", key, [myDictionary objectForKey:key]);

so, for your dictionary this would show

ab => Air Bus
787 => Boeng 787
sp => Some Plane

I'm assuming that you want to show all the values in a table so you will want something like this :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

  // Get a cell
  ...

  // Get the data to display for this cell
  int index = [indexPath indexAtPosition:1];
  NSString *key = [[d allKeys] objectAtIndex:index];
  NSString *value = [d objectForKey:key];
  [[cell textLabel] setText:value];

  return cell;
}
deanWombourne
Thanks, but need to show it on table cellForRowAtIndexPath in each row
iPhoneDev
sorry, I answered while you were editing the question - see my new edit!
deanWombourne
Thanks a lot :)
iPhoneDev