在我的应用中,我必须阅读一个XML文件并将其显示在UITextView
中。为此,我尝试了下面的代码。此代码导致崩溃;谁能告诉我确切的错误?我希望我写得好。请帮帮我。谢谢。
-(IBAction)xmlParse{
NSString *xmlPath=[[[[UIApplication sharedApplication]delegate] applicationDocumentDirectory]stringByAppendingPathComponent:@"xmlFile/toc.xml"];
NSError *error=nil;
NSString *fileContent=[NSString stringWithContentsOfFile:xmlPath usedEncoding:NSASCIIStringEncoding error:NULL];
xmlDisplay.text=fileContent;
}
答案 0 :(得分:4)
替换
NSString *fileContent=[NSString stringWithContentsOfFile:xmlPath usedEncoding:NSASCIIStringEncoding error:NULL];
带
NSString *fileContent=[NSString stringWithContentsOfFile:xmlPath encoding:NSASCIIStringEncoding error:NULL];
您不应忽略编译器向您显示的assing argument 2 of 'stringWithContentsOfFile:usedEncoding:error:' makes pointer from integer without a cast
警告。
答案 1 :(得分:1)
或者你可以尝试
-(IBAction)xmlParse{
NSString *xmlPath=[[[[UIApplication sharedApplication]delegate] applicationDocumentDirectory]stringByAppendingPathComponent:@"xmlFile/toc.xml"];
NSError *error=nil;
NSString *fileContent=[NSString stringWithContentsOfFile:xmlPath usedEncoding:NSASCIIStringEncoding error:NULL];
if(nil!=fileContent)
xmlDisplay.text=fileContent;