- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我遇到了一些非常奇怪的事情:一个方法导致无法识别的选择器发送到实例
,但根本没有NSLog()
任何东西。
我制作了一个自定义的 NSControl 子类,我尝试在其中绘制我的自定义单元格,如下所示:
- (void)drawRect:(NSRect)dirtyRect {
NSLog(@"DrawRect entered!");
[[NSColor grayColor] set];
[NSBezierPath fillRect:[self bounds]];
unsigned int i, count = [cells count];
NSRect cellRect = NSMakeRect(0, 0, ([self bounds]).size.width, cellHeight);
for (i = 0; i < count; i++) {
NSLog(@"Drawing cell %d at: %@", i, NSStringFromRect(cellRect));
MKMenuCell *cell = [cells objectAtIndex:i];
[cell drawWithFrame:cellRect inView:self];
cellRect.origin.y += cellHeight;
}
}
和-[MKMenuCell drawWithFrame:inView:]
:
- (void)drawWithFrame:(NSRect)bounds inView:(NSView *)controlView {
NSLog(@"-drawWithFrame:inView:");
NSMutableDictionary *strAttribs = [[NSMutableDictionary alloc] init];
[strAttribs setObject:[NSColor blackColor] forKey:NSFontAttributeName];
[name drawInRect:bounds withAttributes:strAttribs]; // "unrecognized selector sent ..." is caused by this method call.
}
输出:
2013-03-11 18:46:54.823 MacOverflow[738:a0f] DrawRect entered!
2013-03-11 18:46:54.826 MacOverflow[738:a0f] Drawing cell 0 at: {{0, 0}, {176, 30}}
2013-03-11 18:46:54.826 MacOverflow[738:a0f] -drawWithFrame:inView:
2013-03-11 18:46:54.827 MacOverflow[738:a0f] Drawing cell 1 at: {{0, 30}, {176, 30}}
2013-03-11 18:46:54.828 MacOverflow[738:a0f] -drawWithFrame:inView:
2013-03-11 18:46:54.828 MacOverflow[738:a0f] -[NSCachedWhiteColor screenFontWithRenderingMode:]: unrecognized selector sent to instance 0x100512920
2013-03-11 18:46:54.829 MacOverflow[738:a0f] An uncaught exception was raised
2013-03-11 18:46:54.831 MacOverflow[738:a0f] -[NSCachedWhiteColor screenFontWithRenderingMode:]: unrecognized selector sent to instance 0x100512920
2013-03-11 18:46:54.834 MacOverflow[738:a0f] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCachedWhiteColor screenFontWithRenderingMode:]: unrecognized selector sent to instance 0x100512920'
*** Call stack at first throw:
(
0 CoreFoundation 0x00007fff88c26784 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00007fff858ddf03 objc_exception_throw + 45
2 CoreFoundation 0x00007fff88c80110 +[NSObject(NSObject) doesNotRecognizeSelector:] + 0
3 CoreFoundation 0x00007fff88bf88ef ___forwarding___ + 751
4 CoreFoundation 0x00007fff88bf4a38 _CF_forwarding_prep_0 + 232
5 AppKit 0x00007fff89afcfae +[NSStringDrawingTextStorage _fastDrawString:attributes:length:inRect:graphicsContext:baselineRendering:usesFontLeading:usesScreenFont:typesetterBehavior:paragraphStyle:lineBreakMode:boundingRect:padding:scrollable:] + 402
6 AppKit 0x00007fff896db539 _NSStringDrawingCore + 1588
7 MacOverflow 0x00000001000159b7 -[MKMenuCell drawWithFrame:inView:] + 229
8 MacOverflow 0x0000000100015f1e -[MKMenuControl drawRect:] + 595
9 AppKit 0x00007fff896d6cc5 -[NSView _drawRect:clip:] + 3390
10 AppKit 0x00007fff896d5938 -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 1325
11 AppKit 0x00007fff896d5ca2 -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2199
12 AppKit 0x00007fff896d5ca2 -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2199
13 AppKit 0x00007fff896d5ca2 -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2199
14 AppKit 0x00007fff896d400a -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 767
15 AppKit 0x00007fff896d3b2c -[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 254
16 AppKit 0x00007fff896d03de -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] + 2683
17 AppKit 0x00007fff89649c0e -[NSView displayIfNeeded] + 969
18 AppKit 0x00007fff89611c3b -[NSWindow _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:] + 1050
19 AppKit 0x00007fff896117d2 -[NSWindow orderWindow:relativeTo:] + 94
20 AppKit 0x00007fff895dd974 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1726
21 AppKiProgram received signal: “SIGABRT”.
t 0x00007fff895dba91 loadNib + 226
22 AppKit 0x00007fff895dafa1 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 248
23 AppKit 0x00007fff895dadd9 +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 326
24 AppKit 0x00007fff895d835b NSApplicationMain + 279
25 MacOverflow 0x0000000100000ef9 main + 33
26 MacOverflow 0x0000000100000ed0 start + 52
27 ??? 0x0000000000000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
如您所见,调用了 MKMenuCell
的 drawWithFrame:inView:
。但其 NSLog()
语句的输出未显示。这里发生了什么?如何解决?
编辑:我现在意识到,查看 GDB 输出,第一次没有出错。这让它变得更加陌生。
最佳答案
发送的错误选择器 screenFontWithRenderingMode
是 NSFont 上的一个方法。我敢打赌,您不应该为键 NSFontAttributeName
的值设置颜色。您可能应该给它一个字体。
关于objective-c - NSString 绘制矩形 :withAttributes: causes 'unrecognized selector sent to instance ...' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15345251/
我想知道这两者之间有什么不同 .myClass/DomElement .myotherclassinsidethatelement 和 .myClass/DomElement > .myothercl
使用 jQuery on() 版本 1.7。我通常这样绑定(bind)我的事件: $(".foo").on("click", function() { console.log("foo cli
我想找到与选择器匹配的所有元素,但如果它已经包含在匹配元素中则不查找。 $('#container').find('.child').not('.child .child'); 请注意,.child
我有一个看起来像这样的无序列表,但更广泛: Parent Category 2 Parent Category 2 Parent Category 3
这个问题在这里已经有了答案: CSS negation pseudo-class :not() for parent/ancestor elements (2 个答案) 关闭 4 年前。
我希望使用 CSS :not() 来定位 before 选择器。这可能吗? 示例: https://jsfiddle.net/uuq62b8d/ a.button:before { content
这有什么区别: $.each($('#myTable input[name="deleteItem[]"]:checked').do_something()); 还有这个: $('#myTable i
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我正在使用 UL LI 列表和 jQuery 创建一棵树。我使用了 jQuery 选择器 jQuery(li:has(ul)) 查找所有具有子节点的列表节点,然后向其添加单击事件。 jQuery(li
我真的不知道如何命名这两种方法,所以请原谅我这样调用它们。 字符串选择器 $("#myList li").eq(3); 函数选择器 $("#myList li:eq(3)"); 据我所知,他们都做同样
我有以下代码: .. 我正在使用以下 CSS 来排除具有“main-l tbl”类的表: table:not(.main-l .views-table) { .. } 我注
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicate: What is the difference between $ and jQuery 我注意到使用“jQuery(
我有许多 css 选择器和许多选择器异常,所以我使用 :not 将它们排除在外... 示例(只是一些我不需要的选择器): [class*="-dashboard-"]:not([class$="-bi
CADisplayLink 有这个方法是有道理的,但我很好奇为什么 UIScreen 也会有它。 最佳答案 文档说屏幕提供的显示链接与该屏幕相关联。但是,查看官方文档,与任何屏幕都没有明显的关系;显示
我在这里阅读了关于 toArray() 的文档,并在控制台中对其进行了测试。我找不到在选择器上调用 toArray() 和调用选择器本身之间的区别。 两种方式都得到了完全相同的结果,这是一个与选择器匹
我有一个问题,为什么这两个代码片段不同。 $('#ctl00_DDMenu1_HyperLink1') //jQuery(a#ctl00_DDMenu1_HyperLink1 Default.asp
我想通过以下方式模拟我可以在 jQuery 中实现的目标$('.someClass:not(.hidden)') 我试过下面的代码。 $crawler->filter('someClass:not(.
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我想通过以下方式模拟我可以在 jQuery 中实现的目标$('.someClass:not(.hidden)') 我试过下面的代码。 $crawler->filter('someClass:not(.
我想根据 Iterator::next 中当前枚举变体的某些属性更改枚举变体。我有两次尝试,都没有编译: enum Test { A(Vec), B, } impl Iterator
我是一名优秀的程序员,十分优秀!