开发者

UITableView from plist dictionary KEYS, iOS

I am attempting to get the name of the custom ringtones in the iTunes directory on a jailbroken iPhone. I can开发者_开发百科 successfully list the custom ringtones, but they re displayed as HWYH1.m4r, which is what iTunes renames the files, but I know theres a way to decipher the actual name of the song.

    NSMutableDictionary *custDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/iPhoneOS/private/var/mobile/Media/iTunes_Control/iTunes/Ringtones.plist"];
    NSMutableDictionary *dictionary = [custDict objectForKey:@"Ringtones"];
    NSMutableArray *customRingtone = [[dictionary objectForKey:@"Name"] objectAtIndex:indexPath.row];
    NSLog(@"name: %@",[customRingtone objectAtIndex:indexPath.row]);
    cell.textLabel.text = [customRingtone objectAtIndex:indexPath.row];

dictionary is returning:

"YBRZ.m4r" =     
{
    GUID = 17A52A505A42D076;
    Name = "Wild West";
    "Total Time" = 5037;
};

cell.textLabel.text is returning: name: (null)


NSMutableArray *customRingtone = [[dictionary objectForKey:@"Name"] objectAtIndex:indexPath.row];

That line is totally wrong. Your dictionary object it, in fact, an NSDictionary with keys equal to values like 'YBRZ.m4r'. You are requesting a value for a key named 'Name', which doesn't exist. Then, with that returned object, you are sending it a method as if it were an NSArray, which it isn't. And then you expect that to return an NSArray. Again, I don't think it does. It should be more like this:

NSArray *keys = [dictionary allKeys];
id key = [keys objectAtIndex:indexPath.row];
NSDictionary *customRingtone = [dictionary objectForKey:key];
NSString *name = [customRingtone objectForKey:@"Name"];
cell.textLabel.text = name;

Also note, I'm not using NSMutableDictionarys. If you don't need the dictionary to be mutable, you probably should have a mutable dictionary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜