键不符合键值编码吗?

时间:2014-09-16 00:44:44

标签: ios objective-c

在我的模型基类中,我有一个如此定义的方法:

- (NSDictionary *)propertyDictionary
{
    NSMutableDictionary *props = [NSMutableDictionary dictionary];
    unsigned int outCount, i;
    objc_property_t *properties = class_copyPropertyList([self class], &outCount);
    for (i = 0; i < outCount; i++) {
        objc_property_t property = properties[i];
        NSString *propertyName = [NSString stringWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
        id propertyValue = [self valueForKey:(NSString *)propertyName];
        if (propertyValue) [props setObject:propertyValue forKey:propertyName];
    }
    free(properties);
    return props;
}

现在,直到一两天,这很有效。但是,现在有了某些对象,我突然得到像

这样的异常
this class is not key value coding-compliant for the key title.

奇怪的是,我的类不再具有声明的属性,'title' - 我从对象中删除了该属性。是什么赋予了?为什么我会从class_copyPropertyList获取不正确的属性列表?帮助!

1 个答案:

答案 0 :(得分:0)

啊找到了它!

我将对象声明为符合类别中的<MKAnnotation>。由于该对象不再具有titlesubtitle的自己的访问者,但MKAnnotation需要它们,我得到了崩溃