2

私はObjectiveCを初めて使用するので、無知を許してください。私はこのコードを機能させようとしていますが、役に立ちません。

ヘッダーファイルで、プロパティを宣言しました。

@interface UIWebViewScriptDebugDelegate : NSObject

@property (nonatomic, strong) NSMutableDictionary *sourceIDMap;

@end

私のコードファイルでは、それを合成して初期化します。

@implementation UIWebViewScriptDebugDelegate

@synthesize sourceIDMap = sourceIDMap_;

- (id)init
{
    if ((self = [super init])) {
        self.sourceIDMap = [[NSMutableDictionary alloc] init];
    }

    return self;
}

それは問題なく機能します。NSLog呼び出しを挿入すると、それself.sourceIDMapは確かに辞書であることがわかります。ただし、別のメソッドがプロパティにアクセスしようとした瞬間に、NSMutableDictionaryなくなったように見えます。

- (void) webView:(WebView*)webView
  didParseSource:(NSString*)source
  baseLineNumber:(unsigned int)baseLineNumber
         fromURL:(NSURL*)url
        sourceId:(int)sourceID
     forWebFrame:(WebFrame*)webFrame
{
    // ...

    NSLog(@"Look what we got here:");
    NSLog(@"%@", self.sourceIDMap);
}

時々それはDOMCSSStyleDeclaration、時々それはDOMHTMLHeadElement:です

360 MyApp[49113:1507] Look what we got here:
360 MyApp[49113:1507] <WebScriptObjectPrivate: 0x14540d20>
361 MyApp[49113:1507] -[DOMCSSStyleDeclaration sourceIDMap]: unrecognized selector sent to instance 0xc32e550
361 MyApp[49113:1507] *** WebKit discarded an uncaught exception in the webView:didParseSource:baseLineNumber:fromURL:sourceId:forWebFrame: delegate: <NSInvalidArgumentException> -[DOMCSSStyleDeclaration sourceIDMap]: unrecognized selector sent to instance 0xc32e550
367 MyApp[49113:1507] Look what we got here:
368 MyApp[49113:1507] <WebScriptObjectPrivate: 0x14540ee0>
369 MyApp[49113:1507] -[DOMHTMLHeadElement sourceIDMap]: unrecognized selector sent to instance 0x145ec820
369 MyApp[49113:1507] *** WebKit discarded an uncaught exception in the webView:didParseSource:baseLineNumber:fromURL:sourceId:forWebFrame: delegate: <NSInvalidArgumentException> -[DOMHTMLHeadElement sourceIDMap]: unrecognized selector sent to instance 0x145ec820

どこにありNSMutableDictionaryますか?保持されるはずではないですか?

アップデート

これが役立つ場合は、MonoTouchから呼び出しているARCが有効になっている静的ライブラリにコードがコンパイルされます。

4

1 に答える 1

0

私が追加したwjenで動作しました

objc_setAssociatedObject(sender,
    @"ScriptDebuggerDelegate", delegate, OBJC_ASSOCIATION_RETAIN
    );

で呼び出す前setScriptDebugDelegate:に。senderdidClearWindowObject

称賛は、先端のためにtruillotdechambrierを製造するために行きます。
(私自身もそれをする必要はない releaseようです。)

于 2012-07-18T13:50:23.337 に答える