Dod*_*odo 3 macos cocoa webview
你应该如何使用WebKit的WebView与模态对话框?
[_webView setMainFrameURL:[NSString fromStdString:url]];
[_nsWindow makeKeyAndOrderFront:nil];
return [NSApp runModalForWindow:_nsWindow];
Run Code Online (Sandbox Code Playgroud)
前面的代码仅适用于Mac OS 10.6.使用10.5,这不会导航到指定的URL.没有runModalForWindow,一切正常.
WebView仅适用于主循环,因此在这种情况下不合作.一种解决方案是自己运行模态会话并保持主循环手动(类似于此处提出的).例如:
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];
Run Code Online (Sandbox Code Playgroud)
请注意,您可能希望使用类似的方法-runMode:beforeDate:来降低CPU负载.
| 归档时间: |
|
| 查看次数: |
2382 次 |
| 最近记录: |