Trouble getting NSString from NSDictionary key into UILabel
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 contents of this RecordingsStats are :
{
"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!!
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"];
精彩评论