在模态NSWindow中使用WebView不工作? [英] Using WebView in a modal NSWindow not working?

查看:614
本文介绍了在模态NSWindow中使用WebView不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  [_ webView setMainFrameURL:[NSString fromStdString:url]];如何使用WebKit的WebView? 
[_nsWindow makeKeyAndOrderFront:nil];
return [NSApp runModalForWindow:_nsWindow];

前面的代码仅适用于Mac OS 10.6。使用10.5这不是导航到指定的URL。没有runModalForWindow,一切正常。

解决方案

WebView 主环路并且因此在这种情况下不合作。一个解决方案是自己运行模态会话,并保持主循环手动活动(类似于此处)。例如:

  NSModalSession session = [NSApp beginModalSessionForWindow:yourWindow]; 
int result = NSRunContinuesResponse;

//循环,直到一些结果除了继续:
while(result == NSRunContinuesResponse)
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

//以模态方式运行窗口,直到没有要处理的事件:
result = [NSApp runModalSession:session];

//给主循环一些时间:
[[NSRunLoop currentRunLoop] limitDateForMode:NSDefaultRunLoopMode];

//排除池以避免内存堵塞:
[pool drain];
}

[NSApp endModalSession:session];请注意,你可能想使用 -runMode:beforeDate:


,以保持CPU负载减少。


How should you use WebKit's WebView with a modal dialog?

[_webView setMainFrameURL:[NSString fromStdString:url]];
[_nsWindow makeKeyAndOrderFront:nil];
return [NSApp runModalForWindow:_nsWindow];

The preceeding code is only working on Mac OS 10.6. Using 10.5 this is not navigating to the specified URL. Without the runModalForWindow, everything is working.

解决方案

WebView only works on the main loop and thus doesn't cooperate in this case. One solution would be to run the modal session yourself and keep the main loop manually alive (similar to what is proposed here). E.g.:

NSModalSession session = [NSApp beginModalSessionForWindow:yourWindow];
int result = NSRunContinuesResponse;

// Loop until some result other than continues:
while (result == NSRunContinuesResponse)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    // Run the window modally until there are no events to process:
    result = [NSApp runModalSession:session];

    // Give the main loop some time:
    [[NSRunLoop currentRunLoop] limitDateForMode:NSDefaultRunLoopMode];

    // Drain pool to avoid memory getting clogged:
    [pool drain];
}

[NSApp endModalSession:session];

Note that you probably want to use something like -runMode:beforeDate: instead to keep the CPU load down.

这篇关于在模态NSWindow中使用WebView不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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