코드에 kvc
을 사용합니다.iOS : KVC, 앱을 종료하면 KVC에 문제가 발생합니다
[self addObserver:self forKeyPath:@"type" options:NSKeyValueObservingOptionNew |NSKeyValueObservingOptionOld context:nil];
[self addObserver:self forKeyPath:@"location" options:NSKeyValueObservingOptionNew |NSKeyValueObservingOptionOld context:nil];
그리고 나 또한 여기에 기능을 :
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
if ([keyPath isEqualToString:@"location"] || [keyPath isEqualToString:@"type"]) {
// refresh data
if (self.currentTableView == _sellTableView) {
[self addSellDataSourceWithFlag:1];
}else {
[self addBuyDataSourceWithFlag:1];
}
}
}
의 dealloc에서, 내가 그들을 제거합니다. 내 응용 프로그램을 로그 아웃 할 때
- (void)dealloc {
[self removeObserver:self forKeyPath:@"location"];
[self removeObserver:self forKeyPath:@"type"];
}
그러나이 :
이[self removeObserver:self forKeyPath:@"location"];
문제의 정보는 다음과 같습니다 :
는// exit
- (IBAction)exitButtonPress:(UIButton *)sender {
self.navigationController.navigationBar.hidden = YES;
self.tabBarController.tabBar.hidden = YES;
[[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:@"user_isLogin"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self.tabBarController dismissViewControllerAnimated:YES completion:^{
[self.tabBarController setSelectedIndex:0];
}];
}
문제는 All Exceptions
와 함께, 그것은 행이 표시 될
libc++abi.dylib: terminate_handler unexpectedly threw an exception
그리고 때 bt
I :
(lldb) bt
* thread #1: tid = 0x387c7, 0x000000010a6dbf06 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x000000010a6dbf06 libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x000000010a6a34ec libsystem_pthread.dylib`pthread_kill + 90
frame #2: 0x000000010a43dcec libsystem_c.dylib`abort + 129
frame #3: 0x000000010a23c051 libc++abi.dylib`abort_message + 257
frame #4: 0x000000010a25f292 libc++abi.dylib`std::__terminate(void (*)()) + 44
frame #5: 0x000000010a25eef9 libc++abi.dylib`__cxa_rethrow + 99
frame #6: 0x0000000107b3cf5e libobjc.A.dylib`objc_exception_rethrow + 40
frame #7: 0x000000010831e1b4 CoreFoundation`CFRunLoopRunSpecific + 676
frame #8: 0x000000010a83ead2 GraphicsServices`GSEventRunModal + 161
frame #9: 0x0000000108cc3f09 UIKit`UIApplicationMain + 171
* frame #10: 0x00000001047d5b8f E农通`main(argc=1, argv=0x00007fff5b562638) + 111 at main.m:14
frame #11: 0x000000010a39792d libdyld.dylib`start + 1
frame #12: 0x000000010a39792d libdyld.dylib`start + 1
누군가 kvc
이 문제를 알아? 나는 이것에 대한 해결책이 없으니주의 해 주셔서 감사합니다.
KVC 대신 KVO (Key-Value Observing)를 의미 했습니까? – Andriy
이 관찰을하는 수업은 무엇입니까? 또한 stacktrace가'removeObserver :'문과 일치하지 않습니다 ... – trojanfoe
그리고 KVO를 사용하여 자신의 변경 사항을 모니터링하는 것은 매우 나쁜 생각입니다. 왜 당신은'type'과'location' 메소드를 오버라이드 할 수없고, 슈퍼 구현을 호출하고 데이터를 리프레시 할 수 없습니까? – Andriy