I have a dictionary that hold address details, sometimes it can hold, ‘name, email, telephone’ other times, just ‘name, mobile’
name = "Someone";
email = "Someone@somewhere.com";
telephone = "01000 000000";
or
name = "Someone Else";
mobile = "07700 000000";
I want to display these in a detail table view, in my head this makes sense (I know the below code doesn’t work, but I don’t know any other way of displaying what I want to happen):
if(selectedData objectForKey=@"name" at indexPath.row){
cell.textLabel.text = @"Name";
cell.detailTextLabel.text = [selectedData objectForKey:@"name"];
} else if(selectedData objectForKey=@"email" at indexPath.row){
cell.textLabel.text = @"Email";
cell.detailTextLabel.text = [selectedData objectForKey:@"email"];
} else if(selectedData objectForKey=@"telephone" at indexPath.row){
cell.textLabel.text = @"Telephone";
cell.detailTextLabel.text = [selectedData objectForKey:@"telephone"];
} else if(selectedData objectForKey=@"mobile" at indexPath.row){
cell.textLabel.text = @"Mobile";
cell.detailTextLabel.text = [selectedData objectForKey:@"mobile"];
}
But I can’t seem to get this coded correctly, and I might even be barking up the wrong tree!
Any help or pointers on this welcome.
I have managed to sort this by first adding an array of all the keys within viewdidload:
Then within cellForRowAtIndexPath I used:
PS. don’t forget to set ‘arrayOfKeys’ in your header file.