此类不是键值givenName的键值编码兼容

fla*_*ghi 20 iphone

我有这个

- (void)loadView {
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* databasePath = [documentsPath stringByAppendingPathComponent:@"ProxDeals.db"];
NSError *error;

BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:databasePath];
if (fileExists==TRUE) {
    [[NSBundle mainBundle] loadNibNamed:@"ProxDealsViewController" owner:self options:nil];
}
else {
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"ProxDeals.db"];
    NSLog(@"%@",defaultDBPath);
    success = [fileManager copyItemAtPath:defaultDBPath toPath:databasePath error:&error];
    if (!success) {
        NSAssert1(0, @"Failed to create writable database file with message '%@/.", [error localizedDescription]);
    }
    [[NSBundle mainBundle] loadNibNamed:@"UserRegistration" owner:self options:nil];
}
Run Code Online (Sandbox Code Playgroud)

}

而这个错误:

 Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ProxDealsViewController 0x5f22160> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key givenName.'
Run Code Online (Sandbox Code Playgroud)

我知道我在UserRegistration nib的初始化中没有做些什么,但我不知道如何解决这个问题.

Ada*_*dam 85

这通常意味着某些东西试图访问@property"givenName".

如果你正在做IB的事情,通常的原因是你要么:

  • 从类中删除了该属性,但尚未删除IB中的连接
  • 或者:你有一个文件的所有者对象设置为错误的类(检查属性 - 根据你正在使用的xcode的版本不同 - 找到它设置为的类名.你可能复制/粘贴一个NIB文件,并且没有' t改变NIB中的这个字段),你已经连接了该类的插座,但你的实际文件所有者是不同的东西

  • Apple真的应该考虑改进他们的错误信息. (16认同)