iphone - iOS - 使用关联时出现 "This class is not key value coding-compliant"?

标签 iphone ios objective-c exception key-value-coding

我在我的 iOS 应用程序中声明了以下类...

@interface UserRegistrationRequest : BaseServiceRequest

@property (nonatomic, retain) NSString *username;
@property (nonatomic, retain) NSString *password;
@property (nonatomic, retain) NSString *secretQuestionID;
@property (nonatomic, retain) NSString *secretQuestionAnswer;
@property (nonatomic, retain) UserProfile *profile;

@end


@interface UserProfile : NSObject

@property (nonatomic, retain) NSString *emailAddress;
@property (nonatomic, retain) NSString *firstName;
@property (nonatomic, retain) NSString *lastName;
@property (nonatomic, retain) NSData *profileImage;
@property (nonatomic, retain) NSNumber *dateOfBirth;

@end

据我所知,这些类应该符合键值编码。但是,当我运行以下代码时...
NSString *propKey = @"profile.firstName";
NSString *propVal = [self.registrationRequest valueForKey:propKey];

我得到一个异常(exception)说...
[<UserRegistrationRequest 0xb6187f0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key profile.firstName.

知道为什么会发生这种情况,或者我在排除故障时应该寻找什么?

最佳答案

采用 :

NSString *propVal = [self.registrationRequest valueForKeyPath:propKey];

关于iphone - iOS - 使用关联时出现 "This class is not key value coding-compliant"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15977777/

相关文章:

iOS 从代码 : can't control UIButton titlebar text alignment 添加 UIButton

iphone - 如何在 iPhone 上使用陀螺仪 z 轴?

iphone - 存档类型更改为 Generic Xcode Archive 并且不制作 ipa

ios - 如何在 Windows 上获得真正的 iOS 浏览器模拟?

android - 如何定位 dppx 大于 2 但小于 3 的设备

ios - 在 iOS 8 中重新加载时未调用 UICollectionview cellForItemAtIndexPath

iphone - 从文档目录加载图像

ios - 如何为曲线制作动画

iphone - PhoneGap可以访问iPhone的语音识别软件吗?

android - OpenGL ES 2.0 中的抗锯齿?