【发布时间】:2011-10-25 10:33:49
【问题描述】:
在我的 NSWindowController 子类中,[self window] 为 null。
在我的 nib 文件中,文件所有者(我的子类)和窗口视图之间有一个链接。
为什么会出现这个错误?
当我重构文件所有者的类(NSWindowController 的子类)时,它停止工作。我已经在笔尖中更新了它,所以我不明白它为什么停止工作。
崩溃线:
session = [NSApp beginModalSessionForWindow:[self window]];
2011-10-25 12:27:14.377 MyApp [13161:b0f] *** Assertion failure in -[CBApplication _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo:], /SourceCache/AppKit/AppKit-1138.23/AppKit.subproj/NSApplication.m:3861
2011-10-25 12:27:14.377 MyApp[13161:b0f] An uncaught exception was raised
2011-10-25 12:27:14.378 MyApp[13161:b0f] Modal session requires modal window
2011-10-25 12:27:14.380 MyApp[13161:b0f] (
0 CoreFoundation 0x92e01d87 __raiseError + 231
1 libobjc.A.dylib 0x9317e149 objc_exception_throw + 155
2 CoreFoundation 0x92d69619 +[NSException raise:format:arguments:] + 137
3 Foundation 0x9c41c36f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 AppKit 0x958a987d -[NSApplication _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo:] + 725
5 AppKit 0x958a1973 -[NSApplication beginModalSessionForWindow:] + 72
6 MyApp 0x00042ca3 -[CBWindowController showModal:] + 131
7 MyApp 0x00023c46 -[CBDocument showLinkWindow:shouldLinkAndUpdate:selectedOnly:] + 1174
8 MyApp 0x00023cb1 -[CBDocument linkAllRootItems:] + 81
9 MyApp 0x0002a9b4 -[CBApplicationDelegate linkAllItems:] + 100
10 CoreFoundation 0x92d57091 -[NSObject performSelector:withObject:] + 65
11 AppKit 0x956e1cb3 -[NSApplication sendAction:to:from:] + 232
12 AppKit 0x957d5caf -[NSMenuItem _corePerformAction] + 536
13 AppKit 0x957d592c -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 171
14 AppKit 0x957d4fb5 -[NSMenu _performActionWithHighlightingForItemAtIndex:sendAccessibilityNotification:] + 79
15 AppKit 0x95aaddab -[NSMenu performActionForItemAtIndex:] + 65
16 AppKit 0x95aaddde -[NSMenu _internalPerformActionForItemAtIndex:] + 45
17 AppKit 0x95ab200f -[NSMenuItem _internalPerformActionThroughMenuIfPossible] + 106
18 AppKit 0x9591ba10 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 172
19 AppKit 0x9574a916 NSSLMMenuEventHandler + 452
20 HIToolbox 0x9b175920 _Z22_InvokeEventHandlerUPPP25OpaqueEventHandlerCallRefP14OpaqueEventRefPvPFlS0_S2_S3_E + 36
21 HIToolbox 0x9aff1803 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1602
22 HIToolbox 0x9aff0c80 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 482
23 HIToolbox 0x9b005aa9 SendEventToEventTarget + 76
24 HIToolbox 0x9b175de4 _ZL18SendHICommandEventmPK9HICommandmmhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 482
25 HIToolbox 0x9b175e4e SendMenuCommandWithContextAndModifiers + 70
26 HIToolbox 0x9b1e0697 SendMenuItemSelectedEvent + 275
27 HIToolbox 0x9b0423f9 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 129
28 HIToolbox 0x9b1d1574 _ZL14MenuSelectCoreP8MenuData5PointdmPP13OpaqueMenuRefPt + 608
29 HIToolbox 0x9b03a0b2 _HandleMenuSelection2 + 636
30 HIToolbox 0x9b039e31 _HandleMenuSelection + 53
31 AppKit 0x95646356 _NSHandleCarbonMenuEvent + 302
32 AppKit 0x955d662e _DPSNextEvent + 2196
33 AppKit 0x955d58ab -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 113
34 AppKit 0x955d1c22 -[NSApplication run] + 911
35 AppKit 0x9586618a NSApplicationMain + 1054
36 MyApp 0x000042f4 main + 36
37 MyApp 0x00002e06 start + 54
NSWindowController 是如何创建的:
CBWindowController *windowController = [[subClass alloc] init];
[windowController setRanAsModal:YES];
[windowController setDelegate:self];
[windowController setRootDocument:[NSApp mainWindowDocument]];
[windowController loadWindow];
[windowController centerOnMainWindow:sender];
【问题讨论】:
-
你能显示更多上下文吗,例如什么是 self 以及它是如何制作的,什么是 window 以及它是如何分配的?重构不会更改您已编码的任何 nib 名称(例如 @"MyNibName"),因此这可能是您的问题所在。
-
@jrturton xib 文件的文件名不应更改。我在 xib 文件中更新的是文件所有者类。基本上我已经重构了文件所有者名称类。代码应该可以正常工作。
-
好的,不过有些上下文还是不错的。我的第二个猜测是您在更改文件的所有者类后没有重新连接插座。
-
@jrturton 我所有的 50 个网点都已连接。你是说我应该取消它们的链接并重新连接它们吗? :(
-
50!!只能作为最后的手段,然后!也许只是
window一个,或者检查window在上面的代码行中指向的内容。
标签: objective-c cocoa