I found a strange bug in my code, but I can't reproduce it whenever I want. Sometimes, my iPad app crashes with the following keypath error :
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}";
}
Here is the code that handle the keypath observation :
-(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];
}
and here is where I attach it :
UITextView *tv = [[UITextView alloc] initWithFrame:button.frame];
[tv addObserver:self forKeyPath:@"contentSize" options:(NSKeyValueObservingOptionNew) context:(void *)selected];
textViewCurrentlyEditing = tv;
'selected' being of UIObject type.
I don't use UIWebLayer anywhere in my code. Why is there an objet mutation from UITextView to UIWebLayer ? What am I doing wring ?