关闭NSWindow [英] Closing an NSWindow

查看:885
本文介绍了关闭NSWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



现在,当用户单击WebView上的控件上的按钮时,在我的对象上调用一个Objective C方法。



在这个特定的情况下,按钮的动作是尝试并关闭托管WebView的窗口



[[webView window] close];



这通常是有效的,但有时候我得到一个SEGFAULT或其他访问冲突的事件循环试图dispatcha鼠标消息到现在破坏的视图。



当我尝试关闭窗口时,callstack是可怕的,偶循环已经调用窗口称为webView,在我尝试关闭窗口时调用了我的脚本委托。从对象的回调中销毁对象通常是非常危险的,但是我无法确定用户如何通过与视图交互来安全关闭windows 。

解决方案


callstack是可怕的,当我试图关闭窗口,偶循环调用窗口称为webView,在我尝试关闭窗口时调用了我的脚本委托。从对象的回调中销毁对象通常是很危险的,但是我不知道窗口应该如何安全地关闭,因为用户与它们的视图交互。


您可以使用 performSelector:withObject:afterDelay:关闭窗口,直到按钮按下后0.0秒。


在此特定情况下,按钮的操作是尝试关闭托管WebView的窗口

  [[webView window] close]; 

这通常是有效的,但有时候我得到一个SEGFAULT或其他访问违例循环试图调度鼠标消息到现在已破坏的视图。


这不太可能。事件循环将仅为存在的窗口分派事件;如果你已经关闭并且因此毁坏了一个窗口,没有事件可以到达那个窗口,也没有任何视图可能曾经在其中。



这将有助于如果你将编辑您的问题以包括该崩溃的堆栈跟踪。


I have a NSWindow that hosts a WebView that Ive hooked up to a script handler.

Now, when the user clicks a button on a control on the WebView it calls a Objective C method on my object.

In this specific case, the action of the button is to try and close the window hosting the WebView

[[webView window] close];

This usually works, but sometimes i get a SEGFAULT or some other access violation as a result of the event loop trying to dispatcha mouse message to the now destroyed view.

The callstack is horrible when I try to close the window, the even loop has called the window has called the webView, has called my script delegate when I try and close the window. Destruction of an object from a callback from that object is generally, well, dangerous, but I can't figure out how windows should safely be closed as a result of users interacting with views on them.

解决方案

The callstack is horrible when I try to close the window, the even loop has called the window has called the webView, has called my script delegate when I try and close the window. Destruction of an object from a callback from that object is generally, well, dangerous, but I can't figure out how windows should safely be closed as a result of users interacting with views on them.

You can use performSelector:withObject:afterDelay: to put off closing the window until 0.0 seconds after the button hit.

In this specific case, the action of the button is to try and close the window hosting the WebView

[[webView window] close];

This usually works, but sometimes i get a SEGFAULT or some other access violation as a result of the event loop trying to dispatcha mouse message to the now destroyed view.

That's not likely. The event loop will only dispatch an event for a window that exists; if you have closed and thereby destroyed a window, no event can arrive at that window, nor at any view that may once have been in it.

It would help if you would edit your question to include the stack trace for that crash.

这篇关于关闭NSWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆