<分区>
我是 iPhone 开发的新手,我收到了这个错误输出。我知道发生了什么,只是不知道如何解决。
Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<loginData 0x6b1c> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key UserEMailAddress.'
基本上我正在使用 XML 解析器并尝试将数据存储到我创建的类“loginData”中。我遇到的第一个元素是 UserEMailAddress,代码试图将该值存储到同名的类变量 UserEMailAddress 中。但它抛出了那个错误。
显然,当我创建我的类(class)时出了点问题。不知何故,我猜事情没有正确设置,它无法将数据输入到类(class)中。为了创建 loginData,我所做的只是创建一个文件 -> 新建 -> 类对象。
这是类代码。
登录数据.h
#import <Foundation/Foundation.h>
@interface loginData : NSObject{
NSString *UserEMailAddress;
NSString *SessionUID;
NSString *SessionExpirationUTCDT;
}
@property (nonatomic, retain) NSString *UserEMailAddress;
@property (nonatomic, retain) NSString *SessionUID;
@property (nonatomic, retain) NSString *SessionExpirationUTCDT;
@end
登录数据.m
#import "loginData.h"
@implementation loginData
@synthesize UserEMailAddress=_UserEMailAddress;
@synthesize SessionUID=_SessionUID;
@synthesize SessionExpirationUTCDT=_SessionExpirationUTCDT;
@end
非常简单的东西,没什么太复杂的。
崩溃前访问的最后一个方法在我的 XMLParser 中,它是..
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if (!currentElementValue) {
// init the ad hoc string with the value
currentElementValue = [[NSMutableString alloc] initWithString:string];
} else {
// append value to the ad hoc string
[currentElementValue appendString:string];
}
NSLog(@"Processing value for : %@", string);
}
我确定我在上课时犯了一个小错误,但我不知道那会是什么。提前致谢。
唯一看起来好像变量输入到我的类的方法是这个。
- (void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"LoginResponse"]) {
// We reached the end of the XML document
return;
}
//if ([elementName isEqualToString:@"user"]) {
// We are done with user entry – add the parsed user
// object to our user array
//[users addObject:user];
// release user object
//[user release];
//user = nil;
// }
else {
// The parser hit one of the element values.
// This syntax is possible because User object
// property names match the XML user element names
[loginData setValue:currentElementValue forKey:elementName];
}
currentElementValue = nil;
}