kiran kiran - 2 years ago 145
Objective-C Question

How to access the array dictionary values from mutableArray

how to get value from array of dictionary of key value array.

listMutableArray =[[NSMutableArray alloc] initWithObjects:[NSDictionary dictionaryWithObject:[NSArray
arrayWithObjects:@"kiran",@"1234512345",@"IN", nil] forKey:[NSArray
arrayWithObjects:@"name",@"phone",@"location", nil]],nil];

// set value to tableview cell.

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

// Custom cell declaration completed.
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

NSLog(@"Value of name %@", [[listMutableArray objectAtIndex:indexPath.row] objectForKey:@"name"]);

when print the name key pair from the dictionary array from the mutable array which return nil object.

how to get name phone location values from the mutable array.

Answer Source

Your array formation is wrong Form array like this

NSMutableArray *listMutableArray =[[NSMutableArray alloc] initWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"kiran",@"name",@"1234512345",@"phone",@"IN",@"location", nil], nil];


And In cellForRowAtIndexPath try to print

NSLog(@"Value of name %@", [[listMutableArray objectAtIndex:indexPath.row] objectForKey:@"name"]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download