how to pass local html files using array in xcode

懵懂的女人 提交于 2019-12-02 22:29:09

问题


here i am trying for a application, when i click on the table view it will redirect to another page called details. there I have used a webview to dispaly the selected url value. here is my code

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];

    self.navigationItem.title=@"sample";
    servicesArray=[[NSMutableArray alloc]init];
    [servicesArray addObject:@"1"];
    [servicesArray addObject:@"2"];
    [servicesArray addObject:@"3"];

    urlsArray=[[NSMutableArray alloc]init];
    [urlsArray addObject:@"http://www.google.com"];
    [urlsArray addObject:@"http://www.yahoo.com"];
    [urlsArray addObject:@"http://www.facebook.com"];


}

here instead of urls link i want to pass my local html files. can you please help me out

Thanks chintu.


回答1:


try like this,take all the html file names in Array yourArray.

NSString *htmlFile = [[NSBundle mainBundle] pathForResource:[yourArray objectAtIndex:selectedIndex] ofType:@"html" inDirectory:nil];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[WebView loadHTMLString:htmlString baseURL:nil];


来源:https://stackoverflow.com/questions/17422630/how-to-pass-local-html-files-using-array-in-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!