11
我想將我的html
資源文件的內容放入NSString
對象中。這樣做是否可行?它怎麼能做到?iOS - 如何將HTML資源文件的整個內容讀入NSString *?
我想將我的html
資源文件的內容放入NSString
對象中。這樣做是否可行?它怎麼能做到?iOS - 如何將HTML資源文件的整個內容讀入NSString *?
可能嗎? - 是
是否建議? - 除非它是一個非常大的文件,爲什麼不呢?
怎麼樣? - NSString
- stringWithContentsOfFile:encoding:error:
已經有一種方法可以幫您完成。
請參見下面的代碼片段:
NSError* error = nil;
NSString *path = [[NSBundle mainBundle] pathForResource: @"foo" ofType: @"html"];
NSString *res = [NSString stringWithContentsOfFile: path encoding:NSUTF8StringEncoding error: &error];
不要忘了之後檢查錯誤。並確保將您的HTML文件保存爲UTF8。 – Ahti 2011-12-16 20:53:14
的可能的複製[?如何下載在iPhone上的Objective-C的網頁數據(http://stackoverflow.com/questions/1867002/how-to -download-a-web-page-data-in-objective-c-on-iphone) – rjstelling 2016-11-28 18:24:05