【问题标题】:this class is not key value coding-compliant for the key link [duplicate]此类不符合关键链接的关键值编码[重复]
【发布时间】:2013-09-15 19:11:58
【问题描述】:

我的应用程序崩溃了,请问有什么想法吗?我在我的代码中解析xml,这里是代码。

如果我删除了这条线,它工作正常 [listItem setValue:currentElementValue forKey:elementName]; 谢谢

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{

        if ([elementName isEqualToString:@"channel"]) {
            NSLog(@"found channel");
            app.listArray = [[NSMutableArray alloc]init];
        }
        else if([elementName isEqualToString:@"item"]){
            listItem = [[NewsList alloc] init];
            listItem.title = [attributeDict objectForKey:@"title"];
            listItem.description = [attributeDict objectForKey:@"description"];

        }



    }


    -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
        if (!currentElementValue) {
            currentElementValue = [[NSMutableString alloc] initWithString:string];

        }
        else
            [currentElementValue appendString:string];
    }


    -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
    {
        if ([elementName isEqualToString:@"channel"]) {
            return;
        }

        if ([elementName isEqualToString:@"item"]) {
            [app.listArray addObject:listItem];
            listItem = nil;
        }
        else{
            NSLog(@"element name = %@", elementName);

            [listItem setValue:currentElementValue forKey:elementName];
        }

        currentElementValue = nil;
    }

【问题讨论】:

  • 发帖前请先搜索
  • @trojanfoe,这个问题看起来不同,在我的情况下,我放置了断点,它适用于 4,5 个字段,然后它崩溃了。 NSLog(@"元素名称 = %@", elementName); [listItem setValue:currentElementValue forKey:elementName];我可以看到元素,它多次出现在这里

标签: iphone ios xml ipad


【解决方案1】:

您的对象listItem 属于NewsList 类。由于您在使用setValue:forKey: 时遇到错误,因此此类NewsList 要么没有名称为elementName 和实例变量elementName_elementName 的属性,要么没有实现setter 方法setElementName:。 请检查您是否正确设置了属性,例如使用@property@synthesize

【讨论】:

    猜你喜欢
    • 2017-09-17
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    • 2012-04-26
    • 1970-01-01
    • 2017-10-15
    相关资源
    最近更新 更多