简体   繁体   中英

iphonesdk using tableview and html

im making an application where i have to load my database from html file which is in my resource folder. i have a table view and when i click on a certain cell it will open html file based on that click. can any one help me how to do this. thanks

// create a web view in "cellForRowAtIndexPath"

UIWebView *wv = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,480)];
[wv loadHTMLString: << your html >> baseURL: nil];
wv.delegate = self;

// implement the webView delegate

- (void) webViewDidFinishLoad:(UIWebView *)webView {
    [self.view addSubView:webView];  // or push onto the naviation controller
}

I think when you 'didSelectCellAtIndex' in the table view will open a new view controller with the webview. And you have also mapping of each cell with the corresponding html file name. Then in the viewDidLoad method of your next VC, you can use this code, while webView is the outlet pointing to your UIWebView. And htmlFileName is the html file's name.

  [webView loadRequest:[NSURLRequest requestWithURL:
          [NSURL fileURLWithPath:[[NSBundle mainBundle] 
          pathForResource:htmlFileName 
          ofType:@"html"] 
          isDirectory:NO] ] ];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM