objective-c - 调用[self setValue:forKey:]时应用崩溃

标签 objective-c crash key-value-observing

.h文件

...
@property(nonatomic,readwrite)NSNumber *isConnectionWithServerEstablished;

每当我为isConnectionWithServerIncluded设置setValue时,应用程序崩溃

崩溃点:
[self setValue:Number forKey:@"isConnectionWithServerEstablished"];
输出日志
2012-07-24 16:08:26.517 Protocol[1337:11103] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<__NSMallocBlock__: 0x6b84a70>: An -observeValueForKeyPath:ofObject:change:context: message was received but not handled.
Key path: isConnectionWithServerEstablished
Observed object: <LobbyProtocolModel: 0x6b850b0>
Change: {
   kind = 1;
new = 1;
}
Context: 0x0'

*** First throw call stack:
(0x155e022 0x1b16cd6 0x1506a48 0x15069b9 0xe540ef 0xdc0d91 0xdc0895 0xda633e 0xdc8a82 0xdbcf30 0xdbcedb 0xb606 0xdc0d91 0xdc0895 0xda633e 0xdc16ab 0xe00f19 0xdbcfbf 0xdbcedb 0x5716 0x4d1e 0xe5fa29 0x1529855 0x1529778 0xda419a 0xd5e4 0x24661 0x216d330 0x216ef0c 0x216ecb4 0x216e402 0x9722cb24 0x9722e6fe)
terminate called throwing an exception(lldb) 

最佳答案

正在观察您的对象,但是该对象未实现-observeValueForKeyPath:ofObject:change:context:。如果您要进行手动观察,则观察者需要实现该方法。

关于objective-c - 调用[self setValue:forKey:]时应用崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11629324/

相关文章:

objective-c - 在释放时读取弱指针是否安全?

c# - 为什么我的 "Save"按钮不起作用?

visual-studio - 谁是诺亚·理查兹(Noah Richards),他与VS2010崩溃有什么关系?

swift - Bool 属性无法在 swift 中标记为动态

ios - 具有 KVO View Controller 和基于手势的更改的核心数据对象

iphone - 在 iPhone 的不同 C 函数中访问相同的对象?

ios - 在后台线程上保存到 CoreData Context

perl - Term::ReadLine::Gnu 中 “panic: free from wrong pool during global destruction.” 的原因是什么?

ios - 应用程序崩溃显示 "UITableView was deallocated while key value observers were still registered with it"

objective-c - iOS 应用程序什么时候到达 main() 的末尾?