访问NSDictionary时接收SIGABRT

时间:2011-09-26 16:38:35

标签: ios ios4 plist nsdictionary sigabrt

当使用导航到PLIST的NSDictionary时,我继续收到SIGABRT错误,

**2011-09-26 18:31:01.740 AlarmAppiPhone[3126:10d03] -[__NSCFArray _isNaturallyRTL]: unrecognized selector sent to instance 0x5cb5090
2011-09-26 18:31:01.742 AlarmAppiPhone[3126:10d03] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray _isNaturallyRTL]: unrecognized selector sent to instance 0x5cb5090'**

在这一行,editLabelTextField.text = [alarm objectForKey:ROOT_KEY];我不知道为什么我会这样做。警报是一个NSDictionary,它使用key的对象导航到我已声明的密钥#define ROOT_KEY @"Root"。我在另一个文件中定义了它。 plist看起来有点像这样,

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Root</key>
    <array>
        <dict>
            <key>label</key>
            <string>alarm1</string>
            <key>time</key>
            <date>2011-09-03T07:24:20Z</date>
        </dict>
        <dict>
            <key>label</key>
            <string>alarm2</string>
            <key>time</key>
            <string>2011-09-03T07:24:14Z</string>
        </dict>
    </array>
</dict>
</plist>

1 个答案:

答案 0 :(得分:2)

[alarm objectForKey:@"Root"]会返回NSArray,您尝试将其分配给需要NSString的媒体资源。 (_isNaturallyRTLNSString的特定于iOS的私有函数。)

我假设您正试图前往label。在结构上,这样的访问看起来像这样(您的变量alarm应该被称为alarmPlist):

NSArray *alarms = [alarmPlist objectForKey:@"Root"];
NSDictionary *alarm = [alarms objectAtIndex:0];
editLabelTextField.text = [alarm objectForKey:@"label"];

用不同的索引替换0以访问其他警报。