0

当使用导航到 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,它使用对象作为键来导航到我这样声明的键,#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>
4

1 回答 1

2

[alarm objectForKey:@"Root"]返回一个NSArray,您试图将其分配给一个需要NSString. (_isNaturallyRTL是 iOS 特定的私有函数NSString。)

我假设您正在尝试访问label. 在结构上,这样的访问看起来像这样(你的变量alarm可能应该被调用alarmPlist):

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

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

于 2011-09-26T16:55:17.937 回答