views:

347

answers:

1

I'm attempting to put the value associated with the key called "duration" into a UILabel but I'm getting a blank or "(null)" result showing up in the UILabel.

My NSDictionary object with its keys seems to be logging as being full of the data and keys I think I want, as such:

the content of thisRecordingsStats is { "12:48:25 AM, April 25" = {

FILEPATH = "/Users/brian/Library/Application Support/iPhone Simulator/3.1.3/Applications/97256A91-FC47-4353-AD01-15CD494060DD/Documents/12:48:25 AM, April 25.aif";

duration = "00:04";

applesCountString = 0;

...and so on.

Here's the code where I'm trying to put the NSString into the UILabel:

cell.durationLabel.text = [NSString stringWithFormat:@"%@",[thisRecordingsStats objectForKey:@"duration"]];

I've also tried these other permutations:

cell.durationLabel.text = [thisRecordingsStats objectForKey:@"duration"];

and I've also tried this tag-based approach:

label = (UILabel *)[cell viewWithTag:8];
 label.text = [[thisRecordingsStats objectForKey:@"duration"] objectAtIndex:1];

and:

UILabel *label; label = (UILabel *)[cell viewWithTag:8]; label.text = [NSString stringWithFormat:@"%@",[[thisRecordingsStats objectForKey:@"duration"] objectAtIndex:1]];

I've also tried creating a string from the key's paired value and see a "(null)" value or blankness using that too.

What am I missing? I assume it's something with the formatting of the string. Thanks for looking!!

+1  A: 

I might be jumping the gun a bit but from the look of your log output your NSDictionary is set out as having "12:48:25 AM, April 25" as the key, with another NSDictionary as its value.

i.e.

"12:48:25 AM, April 25" => NSDictionary (
                              FILEPATH => (value)
                              duration => @"00:04"
                           )

etc.

What you need to do is: -

NSDictionary *stats = [thisRecordingsStats objectForKey:@"12:48:25 AM, April 25"];
cell.durationLabel.text = [stats objectForKey:@"duration"];
djhworld
You're correct: I do have a dictionary filled with dictionaries, as I wanted each recording's stats to be accessible by its truncated date of origin string. It now seems my problem is in putting in the code that inserts the dynamic key based upon the date key for each dictionary. Right now I've got something like this returning errors: NSDictionary *stats = [thisRecordingsStats objectForKey:@"%@",[[self.fileList objectAtIndex:[indexPath row] lastPathComponent]stringByDeletingPathExtension]]; but I'll make this a new question. THANKS for your time.
Brian