【问题标题】:UIWebView not loading web pageUIWebView 不加载网页
【发布时间】:2015-08-21 21:00:34
【问题描述】:

我一直在尝试使用 Swift 学习 iOS 开发,但我在尝试加载一个简单的网页一周左右的时间里一直被困住。我环顾四周,以下代码似乎对其他人有用,但是当我运行 iOS 模拟器时,除了 UIWebView 的背景之外什么都没有显示。

class ViewController: UIViewController {

   @IBOutlet weak var myWebView: UIWebView!

   let myURL = NSURL(fileURLWithPath: "https://www.google.com")

   override func viewDidLoad() {
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from a nib.

      myWebView.loadRequest(NSURLRequest(URL: myURL!))
   }

   override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
   }
}

【问题讨论】:

    标签: ios iphone swift uiwebview


    【解决方案1】:

    你应该使用这个

    let myURL = NSURL(string: "https://www.google.com")
    

    不是fileURLWithPath:

    问题是,通过使用fileURLWithPath:,Web 视图在文件系统中搜索名为"https://www.google.com" 的文件,但没有找到,因为不存在这样的文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-21
      • 1970-01-01
      • 2012-02-05
      • 2015-10-14
      • 1970-01-01
      • 2013-02-08
      相关资源
      最近更新 更多