[英]Garbage in (strong) Objective C property inside a delegate
我是目標C的新手,所以請您原諒我的無知。 我試圖使此代碼正常工作,但無濟於事。
在頭文件中,我聲明了一個屬性:
@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的靜態庫中。
我添加了它
objc_setAssociatedObject(sender,
@"ScriptDebuggerDelegate", delegate, OBJC_ASSOCIATION_RETAIN
);
之前調用setScriptDebugDelegate:
對sender
的didClearWindowObject
。
感謝您為truillot de chambrier制作小費。
(似乎我什至不需要自己 release
它。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.