0

コードに奇妙なバグを見つけましたが、いつでも再現できません。時々、私のiPadアプリは次のキーパスエラーでクラッシュします:

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}";
}

キーパス監視を処理するコードは次のとおりです。

-(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;

「選択済み」はUIObjectタイプです。

コードのどこにもUIWebLayerを使用していません。UITextViewからUIWebLayerへのオブジェクトの変更があるのはなぜですか?私は何をしているのですか?

4

2 に答える 2

0

これを試して:

.hファイル(@interfaceファイル)で、UITextView*tvを宣言します。次に、必要に応じてこのコードを記述します。

if(tv)[tv release];
tv = [[UITextView alloc] initWithFrame:button.frame]; 

この方法は、メモリ破損の問題に巻き込まれないようにするのに常に役立ちます。私はそれがあなたのためにトリックをすることを願っています。幸運を!

于 2012-08-24T09:17:17.597 に答える
0

私はこの投稿で解決策を見つけたかもしれないと思います:https ://stackoverflow.com/a/4134583/1128754

「removeFromSuperview」の前に「removeObserver」を追加しました。

    [tv removeObserver:self forKeyPath:@"contentSize"];
于 2012-08-24T11:16:31.140 に答える