我在我的代碼中發現了一個奇怪的錯誤,但無法隨時隨地重現。 有時,下面的keyPath錯誤我的iPad應用程序崩潰:ios:crashValueForKeyPath後崩潰
Keypath contentSize changed
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<UIWebDocumentView: 0x1c9fce00; frame = (0 0; 1034 75); text = 'coucou'; opaque = NO; userInteractionEnabled = NO; layer = <UIWebLayer: 0x1daa9760>>: An -observeValueForKeyPath:ofObject:change:context: message was received but not handled.
Key path: contentSize
Observed object: <UITextView: 0x1da83e60; frame = (32 32; 1034 198); text = 'coucou'; layer = <CALayer: 0x1dad2650>; contentOffset: {0, -62}>
Change: {
kind = 1;
new = "NSSize: {1034, 75}";
}
這裏是處理的keyPath觀察代碼:
-(void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (object != textViewCurrentlyEditing)
return;
NSLog(@"Keypath %@ changed", keyPath);
UITextView *tv = object;
UIObject *selected = (__bridge UIObject *)context;
[self updateTextViewAlign:tv forObject:selected];
}
和這裏就是我將其附加:
UITextView *tv = [[UITextView alloc] initWithFrame:button.frame];
[tv addObserver:self forKeyPath:@"contentSize" options:(NSKeyValueObservingOptionNew) context:(void *)selected];
textViewCurrentlyEditing = tv;
'selected'是UIObject類型。
我不在我的代碼中的任何地方使用UIWebLayer。 爲什麼從UITextView到UIWebLayer有objet變異? 我在幹什麼?
你忘了在其dealloc中註銷你的textview嗎? – borrrden
我的textview並沒有真正取消註冊,因爲我正在使用ARC。 當我不再需要它時,我只需要: [tv removeFromSuperview]; tv = nil; 儀器沒有檢測到任何殭屍,但我猜如果奇怪的textview仍然在某處活着,它還不是殭屍 – Diwann