我有一个大的常量html字符串,我想在我的UIWebView上显示。出于某种原因,当我尝试使用常量字符串(使用@“LARGE_STRING”)时,我得到了一些奇怪的错误,说我在开始时有一个未被提及的'@',我想念终止'''字符,我使用未声明的表达式等等 - 我确实逃避了字符串,至少是“”中的字符串。
我在这里想念的是什么?
TNX!
编辑:示例:
NSString *myString = [NSString stringWithString:@"<title>בסיסי HTML לימוד</title> <META http-equiv="Content-Type" content="text/html; charset=iso-8859-8"> <body bgcolor="#b5deef"bbackground="gifs/rekablue.gif"> <center> <table border=0 cellpadding=0 cellspacing=0> <tr> <td> <table border=0 cellpadding=0 cellspacing=0> <tr> <td> <table border=0 cellpadding=0 cellspacing=0><tr> <td width="246"></td> <td><img src="gifs/lim.gif"></td><td width="50"></td><td><a href="basic1.htm"><img src="gifs/hak.gif" border=0></a></td> </tr></table> <tr><td> <table border=0 cellpadding=0 cellspacing=0><tr> <td width="230"></td> <td><img src="gifs/m.gif"></td><td width="55"></td><td><a href="basic2.htm"><img src="gifs/ktiv.gif" border=0></a></td> </tr></table> <tr><td> <table border=0 cellpadding=0 cellspacing=0><tr> <td width="207"></td> <td><img src="gifs/ud.gif"></td><td width="60"></td><td><a href="basic2.htm"><img src="gifs/amud.gif" border=0></a></td> </tr></table> <tr><td> <table border=0 cellpadding=0 cellspacing=0><tr> <td width="163"></td> <td><img src="gifs/tl.gif"></td><td width="55"></td><td><a href="basic2.htm"><img src="gifs/reshon.gif" border=0></a></td> </tr></table> <tr><td> <table border=0 cellpadding=0 cellspacing=0><tr> <td width="133"></td> <td><img src="gifs/ml.gif"></td><td width="55"></td><td><a href="basic3.htm"><img src="gifs/text1.gif" border=0></a></td> </tr></table> <tr><td> <table border=0 cellpadding=0 cellspacing=0><tr> <td width="108"></td> <td><img src="gifs/t.gif"></td><td width="35"></td><td><a href="basic4.htm"><img src="gifs/kish.gif" border=0></a></td> </tr></table> <tr><td> <table border=0 cellpadding=0 cellspacing=0><tr> <td width="93"></td> <td><img src="gifs/h.gif"></td><td width="35"></td><td><a href="basic5.htm"><img src="gifs/reshim1.gif" border=0></a></td> </tr></table> <tr><td> <table border=0 cellpadding=0 cellspacing=0><tr> <td width="70"></td> <td><img src="gifs/b.gif"></td><td width="42"></td><td><a href="basic6.htm"><img src="gifs/tmunot.gif" border=0></a></td> </tr></table> <tr><td> <table border=0 cellpadding=0 cellspacing=0><tr> <td width="40"></td> <td><img src="gifs/s.gif"></td><td width="53"></td><td><a href="basic7.htm"><img src="gifs/rekaim1.gif" border=0></a></td> </tr></table> <tr><td> <table border=0 cellpadding=0 cellspacing=0><tr> <td width="10"></td> <td><img src="gifs/s1.gif"></td><td width="45"></td><td><a href="basic9.htm"><img src="gifs/tfasim.gif" border=0></a></td> </tr></table> <tr><td> <table border=0 cellpadding=0 cellspacing=0><tr> <td width="8"></td> <td valign=top><img src="gifs/si.gif"></td><td width="30"></td><td><a href="basic8.htm" border=0><img src="gifs/tavlaot.gif" border=0></a></td> </tr></table> </td></tr> </table> </td> <td valign=bottom><a href="default.htm" onMouseOver="self.status='חזרה לעמוד פתיחה';return true" onMouseOut="self.status='';return true"><img src="gifs/shtml11.gif" border=0></a>&nbsp;&nbsp;&nbsp;<a href="bm_guide.htm#html" onMouseOver="self.status='אתרים נוספים';return true" onMouseOut="self.status='';return true"><img src="gifs/shtml10.gif" border=0></a></td></tr></table> </center> </body>"];
答案 0 :(得分:2)
如果你有“字符串中的字符,那么你必须逃避它们:
NSString *myString = @"This string contains \"quotes\". If they are not \"escaped\", that will cause errors".
或者,另一种可能性是,您正在使用#defines,如
#define LARGE_STRING "This is an extremely large string (well, OK, not so large)"
然后你应该做
#define LARGE_STRING @"This is an extremely large string (well, OK, not so large)"
和
NSString *myString = LARGE_STRING;
"
代码而不是硬编码的"
字符。只要确保你的字符串(确实很长)没有用硬线包裹。
我刚试过,你的例子在Objective-C(Xcode 4.1)中编译得很好。请注意,如果您尝试将此类字符串传递给C函数,则应首先将其转换为有效的C字符串。