asked    Susan     2018-10-22       ios       25 view        1 Answer

[SOLVED] How can i add multiple HTML files to WebKit View?


I'm designing a historical application.I want to add multiple HTML files into WebKit View. I don't have any idea how to do this.


When I click to "Button 1" webkit loads "file1.html". I didn't write anything about code I am quite confused. Any help would be appreciated.

  1 Answer  

        answered    Ingram     2018-10-22      

Well, there is a lot of ways to do it but I'm gonna give an example for easiest one. Just create a method for loading .html file and invoke or call it under action button.

For example :

import UIKit
import WebKit

class ExampleController: UIViewController {

@IBOutlet weak var myButton: UIButton!
@IBOutlet weak var webView: WKWebView!

override func viewDidLoad() {

    webView.navigationDelegate = self


@IBAction func firstButtonPressed(_ sender: UIButton) {
    // Here you can call your method to load html page.
    loadPage(pageName: "privacy_policy")        

@IBAction func secondButtonPressed(_ sender: UIButton) {
     // Here you can call different html page.
    loadPage(pageName: "terms")

// With this method you can call html page by it name (as parameter)
fileprivate func loadPage(pageName: String) {
    let url = Bundle.main.url(forResource: pageName, withExtension: "html")
    // file url is ready lets to add it as parameter for webView.
    webView.loadFileURL(url!, allowingReadAccessTo: url!)

extension AboutAppController: WKNavigationDelegate {

   func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
       // Here you can add start your animations (like activity indicator)

   func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
       // And here finish your animations.

Your Answer

 2018-10-22         Darren

How to pass string in the url as a parameter for core api

I am trying to build an api that will take a IForm file from the body and save the file. Then return the filename in the directory. I have worked with the same structure before. But then I had an integer value in the parameter now it is a string. I am trying this way. But when the route matches it always returning status 200 without saving the file and filename in the respond. [HttpPost][Route("/api/users/${email}/photos")]public async Task<IActionResult> Upload(string email, [FromBody]IFormFile fileStream){ var user = this.repository.GetUserByEmail(email); if (...
 c#                     1 answers                     102 view
 2018-10-22         Stacey

Inject User Credentials from HttpRequestContext into the service layer

I have a .NET 4.6 WebApi 2.0 OWIN App that serves HTTP Requests.Those requests are authenticated and we are storing certain claims in the RequestContext ClaimsIdentity (UserId, Client Code)We also have our Controllers, Services and Repository structure.Our Services are injected into the Controllers via Ninject, and the Repositories into the Services.When the user performers certain requests we need to check their permissions. The service usually needs to know the: UserId, ClientCode, Groups the user has access to and permissions under each group (Read, Write, etc). This las...
 c#                     2 answers                     102 view
 2018-10-22         Omar

File.Exists returns true on file name only

I am currently debugging an application, where the following code returns true on the file name only. If Not IO.File.Exists(out) Then '' WorkEnd IfThe watches for this execution is as follows:How is this statement validated as true, when the actual file is located fairly deep on a network drive? I'd assume that this could be true, if the file was located in the same directory as my execution. Documentation: File.Exists the path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the curren...
 .net                     1 answers                     102 view