Objective c 委托内的(强)目标C属性中的垃圾
我对目标C不熟悉,所以我恳请原谅我的无知。 我想去上班,但没用 在头文件中,我声明了一个属性:Objective c 委托内的(强)目标C属性中的垃圾,objective-c,ios,ios5,automatic-ref-counting,Objective C,Ios,Ios5,Automatic Ref Counting,我对目标C不熟悉,所以我恳请原谅我的无知。 我想去上班,但没用 在头文件中,我声明了一个属性: @interface UIWebViewScriptDebugDelegate : NSObject @property (nonatomic, strong) NSMutableDictionary *sourceIDMap; @end 在我的代码文件中,我合成并初始化它: @implementation UIWebViewScriptDebugDelegate @synthesize so
@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);
}
有时它是一个domcssstyle声明
,有时它是一个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
360 MyApp[49113:1507]看看我们在这里得到了什么:
360 MyApp[49113:1507]
361 MyApp[49113:1507]-[DOMCSSStyleDeclaration sourceIDMap]:发送到实例0xc32e550的无法识别的选择器
361 MyApp[49113:1507]***WebKit丢弃了webView:didParseSource:baseLineNumber:fromURL:sourceId:forWebFrame:delegate:-[DOMCSSStyleDeclaration sourceIDMap]:发送到实例0xc32e550的无法识别的选择器中的未捕获异常
367 MyApp[49113:1507]看看我们在这里得到了什么:
368 MyApp[49113:1507]
369 MyApp[49113:1507]-[DOMHTMLHeadElement sourceIDMap]:发送到实例0x145ec820的选择器无法识别
369 MyApp[49113:1507]***WebKit丢弃了webView:didParseSource:baseLineNumber:fromURL:sourceId:forWebFrame:delegate:-[DOMHTMLHeadElement sourceIDMap]:发送到实例0x145ec820的无法识别的选择器中的未捕获异常
NSMutableDictionary
在哪里?不是应该保留吗
更新
如果这有帮助的话,代码将被编译到一个静态库中,并启用了我从MonoTouch调用的ARC。我补充道,它工作正常
objc_setAssociatedObject(sender,
@"ScriptDebuggerDelegate", delegate, OBJC_ASSOCIATION_RETAIN
);
在调用didClearWindowObject
中的sender
上的setScriptDebugDelegate:
之前
小费值得称赞。(好像我自己发布了它。)我补充道,它起了作用
objc_setAssociatedObject(sender,
@"ScriptDebuggerDelegate", delegate, OBJC_ASSOCIATION_RETAIN
);
在调用didClearWindowObject
中的sender
上的setScriptDebugDelegate:
之前
小费值得称赞。(好像是我自己发布的。)你能把代码放在你把数据放在NSMutableArray里的地方吗?@MrBr:关键是:我没有。我删除了访问字典的所有代码,但创建字典的
init
和测试字典的didpassessource
除外。是否确实正确保留了UIWebViewScriptDebugDelegate?(尝试使用NSZombies)我还假设这与数组本身无关,而是与附加到数组中的对象有关。@fabrice:我不是。我假设如果不保留委托,代码就不会被调用。我不知道僵尸是什么,所以请给我一些时间来谷歌一下并跟进。谢谢。你能在NSMutableArray中准确放置数据的地方发布代码吗?@MrBr:关键是:我不知道。我删除了访问字典的所有代码,但创建字典的init
和测试字典的didpassessource
除外。是否确实正确保留了UIWebViewScriptDebugDelegate?(尝试使用NSZombies)我还假设这与数组本身无关,而是与附加到数组中的对象有关。@fabrice:我不是。我假设如果不保留委托,代码就不会被调用。我不知道僵尸是什么,所以请给我一些时间来谷歌一下并跟进。谢谢