我是Objective 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
?不应该保留吗?
更新
如果这有帮助,代码将被编译成一个启用了 ARC 的静态库,我从 MonoTouch 调用该库。