ios - AppDelegate:此类与键的键值编码不兼容---

标签 ios objective-c appdelegate key-value-coding

AppDelegate.h我创建了以下属性,

@property (strong, nonatomic) NSMutableDictionary *googleUserDetailsDictionary;

AppDelegate.m ,

static NSString *kGoogleDetails = @"googleDetails"; @synthesize googleUserDetailsDictionary;

我在 AppDelegate.m 中创建了一个自定义方法我在其中添加了以下行: [self setValue:googleUserDetailsDictionary forKey:kGoogleDetails];

在我想成为 googleUserDetailsDictionary 的观察者的 ViewController 中属性(property),

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; [appDelegate addObserver:self forKeyPath:@"googleUserDetailsDictionary" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:kGoogleDetails]) {
        NSLog(@"This is change taking place: %@ \t\t", change);

    }
}

然后,当我尝试打开 ViewController 时,出现以下错误: ** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FIRA_AppDelegate-1470253453284 0x7fd4fa839410> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key googleDetails.'

最佳答案

我相信它告诉你真相。您没有任何名为 googleDetails 的属性。

尝试更改 key 路径以匹配属性,例如:

static NSString *kGoogleDetails = @"googleUserDetailsDictionary";

关于ios - AppDelegate:此类与键的键值编码不兼容---,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38752162/

相关文章:

ios - 如何在不重复代码的情况下在所有 Controller 中显示警报?

ios - ASIFormDataRequest POST 不起作用

ios - 添加对在 XML 文件中保存数据的应用程序的搜索

ios - 在 ImageView 中缩放图像 (Scale x,y) - IOS

ios - 容器 View Controller 中的 IBAction

swift - 如何使用 swift 在应用程序委托(delegate)函数中使用 toast 方法

ios - 我们可以为同一个应用程序同时使用 Apple iOS8 Testflight 和 HockeyApp 吗?

iphone - Objective-C - 检查 URL 是否存在

iphone - 子类化实现 MKMapViewDelegate 的类,但未调用 MKMapViewDelegate 方法

xcode - 突然出现AppDelegate.h错误