Description of WebViews

Hi Guys,
I am struggling with webView. I have been able to create a separate tab for WkWbView and have been able to display bignerdranch website. but this is all just a copy paste from web. Any way to develop an understanding of all of these.

Here is the code i used

[code]import UIKit
import WebKit

class WebViewController: UIViewController, WKNavigationDelegate {
var webView: WKWebView!
override func loadView() {
webView = WKWebView()
webView.navigationDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL(string: “https://www.bignerdranch.com”)!
webView.loadRequest(NSURLRequest(URL: url))
webView.allowsBackForwardNavigationGestures = true
print(“WebViewController loaded its view”)
}

}[/code]

  1. Do you know another programming language?

  2. Have you ever done any web programming in that language?

@NikhiliOS,

Why did you put the configuration for the WebView in viewDidLoad()? The book configures the MapView in loadView().

[quote=“7stud7stud”]@NikhiliOS,

Why did you put the configuration for the WebView in viewDidLoad()? The book configures the MapView in loadView().[/quote]

[quote]Any way to develop an understanding of all of these.

  1. Do you know another programming language?

  2. Have you ever done any web programming in that language?[/quote]

Hi
I had learnt basics of C ,which is ages ago . Other than this I am dabbling with Swift. I put that in viewdidload coz there is an explanation for that in hacking with swift (Project 4). Rest I am just trying to figure my way out.

Okay, thanks. That website doesn’t explain why they put the configuration code in viewDidLoad() rather than loadView() like the book does.

Both of these functions are delegates of the UIViewController class, but get called at different times and are used for different purposes. If you Command-click on the UIViewController protocol declaration, you will see all of the delegates and their explanations.

The viewDidLoad method gets automatically run after the view loads, and is called after loadView as shown in the comments for the method:

public func viewDidLoad() // Called after the view has been loaded. For view controllers created in code, this is after -loadView. For view controllers unarchived from a nib, this is after the view is set.
In the example of WorldTrotter, we added the UISegmentedControl to the view, which is indeed a change to the hierarchy.

The loadView method is used when you want to create a custom hierarchy in the view, as explained here:

public func loadView() // This is where subclasses should create their custom view hierarchy if they aren't using a nib. Should never be called directly.
I hope this helps to clarify the difference for you.

@NikhiliOS,

Ah, sorry. I didn’t realize you were the person that asked the original question.

[quote]I am struggling with webView. I have been able to create a separate tab for WkWbView and have been able to display bignerdranch website. but this is all just a copy paste from web. Any way to develop an understanding of all of these.
[/quote]
You need to know how the internet works. Computers on the internet need to talk to each other, so they use a very limited set of commands to make it easy to understand each other. Those limited set of commands are known as the “http protocol”. An http command is just some text in a certain format that is sent out over the internet to another computer.

A web browser, like Safari, is just a computer program that uses http commands to fetch a page of text from another computer. The page of text is written in html, and when a browser receives a page of text from another computer, the browser converts the text into all the beautiful colors and pictures you see on a web page. To get a page of text from another computer, the browser sends out what is known as a request. The page of text that is returned is known as a response. In order to direct the request to the proper computer, the request has to contain an address, known as a URL.

The code you used for your WebView constructs a URL object(which allows you to access pieces of the url), and then the code uses the URL object to create a Request object–to create a Request object, you have to use a URL object because the Request object needs to retrieve pieces of the url. A Request object takes care of formatting the request according to a format specified by the http protocol, which is the format that the other computer is expecting. Finally, the code sends the request out over the internet using the loadRequest() method. Another computer somewhere on the internet receives the request, then sends a response back to your iPhone, or in this case the iPhone simulator, which then gives the page of text to your app. A WebView knows what to do with a response–it converts the text into a web page and displays it.

If you want to know anything more specific, ask away.