如何在WebView中显示NSString内容(可可Mac应用程序) [英] How to display NSString content in WebView (Cocoa Mac app)

查看:62
本文介绍了如何在WebView中显示NSString内容(可可Mac应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用NSString中的文本加载WebView?如果我将字符串内容保存到文件中,然后使用类似以下内容的话:

Is it possible to load a WebView with the text from a NSString? If I save the string content into a file and then use something like:

[[main_browser mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"file:///Volumes/AA/myfile.txt"]]]; 

它可以工作,但是如何在不将内容写入文件的情况下实现呢?

It works, but how can I do it without writing the content into a file?

推荐答案

是的,您可以将NSString加载到Web视图中,只需查看以下方法即可:

Yeah you can load a NSString into a webview, just look at the following method:

- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL

您还可以通过创建NSString对象,然后将其加载到webview中,以这种方式从磁盘打开文件.但是,使用loadRequest可能更好(因为它在做相同的事情,但是在内部).

You can also open files from the disk this way by creating a NSString object and then loading it into the webview. However using loadRequest might be better ( as it is doing the same thing, but then internally ).

如果要将NSString写入文件,则可以:

If you want to write a NSString to a file you can:

[someStringObject writeToFile:_path_];

您实际上看过NSString类参考吗?那里很清楚.

Did you actually take a look at the NSString class reference? It is pretty clear there.

这篇关于如何在WebView中显示NSString内容(可可Mac应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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