some disapointement with uiwebview, for very simple code
class ViewController: UIViewController {
#IBOutlet weak var mavue: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let requestURL = NSURL(string: "http://www.google.com")
let request = NSURLRequest(URL: requestURL!)
mavue?.loadRequest(request)
println("myWebView : \(mavue)")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
println("myWebView : (mavue)") return nil
i try it on simulator, i have loaded my controllerview from presentViewController maybe it's the reason why?
but my code doesn't show mywebview.
mywebView is connected to my IBoutlet
thank
EDIT : It 's work, I think that th mistake was to keep the default uiviewcontroller , when i use a subclass all is ok
Thank
Related
I've scoured the internet for 3 hours now, and have just given up. I figured since no one else on this entire planet has had this problem before, maybe I should ask the stackoverflow community, and see what happens.
I'm familiar with xCode, and objective C, but am learning swift. For my first app I figured I'd build a super simple webview app that loads a page. Easy right? I can code this in about 15 seconds in objective c, and I did, it works fine. Maybe there's something I'm missing here.
When I attempt to connect the object to the UIWebView it won't connect.
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
#IBOutlet var webView: WKWebView!
#IBOutlet var textBox: UITextField!
override func loadView() {
webView = WKWebView()
webView.navigationDelegate = self
view = webView
}
override func viewDidLoad() {
let url = NSURL(string: "https://www.google.com")!
webView.loadRequest(NSURLRequest(URL: url))
webView.allowsBackForwardNavigationGestures = true
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Image of it not connecting. It's not connecting like it should
Change type from WKWebView to UIWebView.You have added UIWebView from object library which your are trying to connect to a WKWebView object so it will not connect. WKWebview has to be added programmatically as it is not present in object library.
These two classes have similar functionalities but they are not connected to each other in anyway.
You can use the following code to build a webView app that loads a page.
import UIKit
class ADKWebViewDemoViewController: UIViewController {
#IBOutlet weak var webview: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
webview.loadRequest(NSURLRequest(URL: NSURL(string: "https://www.google.com")!))
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I am currently having this issue with IOS app.
When I click on a URL button the UIWebView loads the correct URL in first instance however when I visit another page within same Web View Frame it stores that page to its memory. When I navigate to another button and click back to previous button it shows the page that I was previously in instead of loading the URL.
What I want to achieve is when user clicks on button the UIWebView loads the URL .
My current code:
import UIKit
class MenuViewController: UIViewController {
#IBOutlet weak var oyebWebView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
oyebWebView.loadRequest(NSURLRequest(URL: NSURL(string: MenuUrl)!))
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
You can use following code it will work.
import UIKit
class MenuViewController: UIViewController {
#IBOutlet weak var oyebWebView: UIWebView!
override func viewWillAppear(animated: Bool) {
let webUrl : NSURL = NSURL(string: MenuUrl)!
let webRequest : NSURLRequest = NSURLRequest(URL: webUrl)
oyebWebView.loadRequest(webRequest);
}
override func viewDidLoad() {
// super.viewDidLoad()
//super.viewWillAppear(YES)
// self.viewDidAppear(true)
let webUrl : NSURL = NSURL(string: MenuUrl)!
let webRequest : NSURLRequest = NSURLRequest(URL: webUrl)
oyebWebView.loadRequest(webRequest);
//oyebWebView.loadRequest(NSURLRequest(URL: NSURL(string: MenuUrl)!))
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
I have loaded a webpage to xcode WebView. But only the upper portion of the page is loaded. I can not scroll down to the bottom of the page. Same fact for pdf. Only upper 2 pages can be scrolled. What can i do ?Here is my code.
Thanks in advance.
import UIKit
class ViewController: UIViewController {
#IBOutlet var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
var URL = NSURL(string: "http://www.archetapp.com")
webView.loadRequest(NSURLRequest(URL: URL!))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
//for pdf
import UIKit
class ViewController: UIViewController {
#IBOutlet var webViews: UIWebView!
var path = ""
override func viewDidLoad() {
super.viewDidLoad()
path = NSBundle.mainBundle().pathForResource("ibook", ofType: "pdf")!
let url = NSURL.fileURLWithPath(path)
webViews.scalesPageToFit = true
webViews.scrollView.scrollEnabled = true
webViews.userInteractionEnabled = true
self.webViews.loadRequest(NSURLRequest(URL: url!))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Try this!
import UIKit
class ViewController: UIViewController, UIWebViewDelegate {
#IBOutlet var webView : UIWebView
override func viewDidLoad() {
super.viewDidLoad()
//load initial
path = NSBundle.mainBundle().pathForResource("ibook", ofType: "pdf")!
let url = NSURL.fileURLWithPath(path)
var req = NSURLRequest(URL : url)
webView.delegate = self // <---
webView.loadRequest(req)
}
func webViewDidStartLoad(webView : UIWebView) {
//UIApplication.sharedApplication().networkActivityIndicatorVisible = true
println("webViewDidStartLoad")
}
func webViewDidFinishLoad(webView : UIWebView) {
//UIApplication.sharedApplication().networkActivityIndicatorVisible = false
webViews.scalesPageToFit = true
webViews.scrollView.scrollEnabled = true
webViews.userInteractionEnabled = true
println("webViewDidFinishLoad")
}
}
I had the same issue just today and at least in my case it was caused by having the "Scale Pages to Fit" option checked in the WebView properties. I'm assuming Carlos' reply regarding the zoom scale fixes it anyways but I didn't need the option enabled in the first place so that was my easy fix.
I've made in Swift a webview & in that webview there are links to ics file on the same domain of the webview. Now, when you click this link in Safari, you can perfectly add this to your calendar, but when I try this in iOS simulator, or on my device, I can't 'open' the ICS file link.
Any idea what I am doing wrong? Thanks!
This is my code:
import UIKit
class FirstViewController: UIViewController {
#IBOutlet weak var webAgenda: UIWebView!
#IBOutlet weak var activityagenda: UIActivityIndicatorView!
var url = "http://******.be/agenda.php"
func loadURL () {
let requestURL = NSURL(string: url)
let request = NSURLRequest(URL: requestURL!)
webAgenda.loadRequest(request)
}
override func viewDidLoad() {
super.viewDidLoad()
loadURL()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func webViewDidStartLoad(webView: UIWebView) {
activityagenda.hidden = false
activityagenda.startAnimating()
}
func webViewDidFinishLoad(webView: UIWebView) {
activityagenda.hidden = true
activityagenda.stopAnimating()
}
because you load a http site so in iOS9 will have problem with App Transport Security.
disable ATS here
I am hoping someone maybe able to help, I am new too Xcode and have been trying relentlessly to execute the following URL in webview and not having much luck:
http://view.vzaar.com/5532785/player
Below is the code:
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL (string: "http://view.vzaar.com/5532785/player")
let requestObj = NSURLRequest(URL: url!);
webView.loadRequest(requestObj)
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Any suggestions would be really appreciated.
Jon
Try this,
If you using Xcode 7(swift 2). Add following details in your plist