4

a button's IBAction in windowA calls runModalForWindow:windowB.

windowB becomes key and modal.

windowB has a popUpWindowDatePicker which calls stopModal upon display, and then popUpWindowDatePicker becomes key, and windowB resigns key and is not modal. no window is modal at this point.

when popUpWindowDatePicker is dismissed, its didResignFirstResponder method sets a boolean to YES. windowB then becomes key, and windowB's windowController windowDidBecomeKeyNotification fires, checks the boolean value and if it is YES calls runModalForWindow:self.window.

now windowB is modal and key. windowA is still open, but not key.

windowB has Okay and Cancel buttons which call: [NSApp stopModalWithCode:returnCode] and then orderOut: and close on windowB.

if the popUpWindowDatePicker is used, and then any time after that windowB is closed with Okay or Cancel, an Assertion Failure is called involving the Okay or Cancel buttons:

*** Assertion failure in -[NSButton lockFocus], /SourceCache/AppKit/AppKit-1038.29/AppKit.subproj/NSView.m:5237

-[NSButton(0x20021cd60) lockFocus] failed with window=0x20021c0c0, windowNumber=-1, [self isHiddenOrHasHiddenAncestor]=0

if windowB is closed with Okay or Cancel and popUpWindowDatePicker has not been used, there is no assertion failure.

it seems that the sequence runModal-stopModal-runModal-stopModal on windowB is involved in the failure of lockFocus on the button pressed, but i can't find a way to trace down more than this to solve this problem.

can anyone offer any hints or thoughts?

4

4 回答 4

2

在对带有大量文本的 NSTextView 进行绘图时,我遇到了类似的问题。解决此消息和其他与“失去焦点”或调用“错误对象”相关的崩溃的方法是:从核心动画层移除对象(以及它可能拥有的任何子对象)。

为了在我的 NSTextView 上执行此操作,我在 UIbuilder 上轻松取消了任何动画的选中,这是与核心动画层相对应的实用程序面板中的最后一个选项卡。

希望能帮助到你,

于 2013-02-06T16:15:44.217 回答
0

这里有类似的问题。我的问题是我的项目(tableView)失去了焦点。我所做的是将我的 tableView 指定为 firstReponder 以便它再次获得焦点。

//...some code...
[self.searchTableView reloadData];
AGAppDelegate *del = [[NSApplication sharedApplication] delegate];
[del.window makeFirstResponder:self.searchTableView];

希望这会对某人有所帮助。

于 2012-09-27T18:20:00.230 回答
0

我遇到了类似的问题,这里是我的日志:

* -[NSSecureTextField lockFocus] 中的断言失败,/SourceCache/AppKit/AppKit-1038.36/AppKit.subproj/NSView.m:5237

[13755:903] unlockFocus 调用的时间过多。

[13755:903] unlockFocus 调用的时间过多。

[13755:903] -[NSSecureTextField(0x100514b80) lockFocus] 失败,window=0x1005298d0,windowNumber=714,[self isHiddenOrHasHiddenAncestor]=1

似乎它是Lion OS X之前的错误,因为我已经升级到Lion它已经消失了......我猜它发生在未定义的showModal序列(在我的例子中是NSMenu)和NSWindow orderOut的某个点程序执行之后. 之后应用程序继续工作,但变得不稳定,例如计时器可能会停止,或者 UI 停止重绘(但仍然有效)。

于 2012-03-14T13:49:30.557 回答
0

我添加了一种canDraw方法来确保lockFocus可用。这解决了我的问题。

于 2017-12-04T11:49:48.270 回答