【问题标题】:UITableView from plist dictionary KEYS, iOS来自 plist 字典 KEYS、iOS 的 UITableView
【发布时间】:2009-12-28 23:43:04
【问题描述】:

我正在尝试获取越狱 iPhone 上 iTunes 目录中自定义铃声的名称。我可以成功列出自定义铃声,但它们重新显示为HWYH1.m4r,这是 iTunes 重命名文件的原因,但我知道有一种方法可以破译歌曲的实际名称。

    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 正在返回:

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

cell.textLabel.text 正在返回:name: (null)

【问题讨论】:

  • 我怎样才能 cell.textLabel = 数组中的名称?

标签: ios nsarray key plist jailbreak


【解决方案1】:
NSMutableArray *customRingtone = [[dictionary objectForKey:@"Name"] objectAtIndex:indexPath.row];

那句话是完全错误的。您的dictionary 反对它,实际上,它是一个 NSDictionary,其键值等于“YBRZ.m4r”之类的值。您正在请求一个名为“名称”的键的值,该键不存在。然后,使用返回的对象,您将向它发送一个方法,就好像它是一个 NSArray,但事实并非如此。然后你期望它返回一个NSArray。再说一次,我认为不会。它应该更像这样:

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

另外请注意,我没有使用NSMutableDictionarys。如果你不需要字典是可变的,你可能应该有一个可变字典。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-13
    • 1970-01-01
    相关资源
    最近更新 更多