【发布时间】:2017-01-24 13:32:43
【问题描述】:
我正在尝试制作一个带有启动 web 视图的按钮的应用程序。
我已经学习了许多教程并阅读了有关该主题的不同主题,但我无法使其正常工作:我在测试代码时收到此消息:
"Cannot call value of non-function type UIWebView!"
这是我到现在为止的步骤
- 在主视图控制器中添加按钮
- 创建另一个名为“WebViewController”的视图控制器
- 添加一个 segue 以将按钮链接到 WebViewController
- 创建一个新的 Cocoa Touch 类文件 'WebViewController'
- 使用 WebViewController 类设置 WebViewController 自定义类
- 在名为“myWebView”的 WebViewController ViewController 中添加 webView
这是 WebViewController 类(我在运行项目时遇到了错误)
import UIKit
class WebViewController: UIViewController{
@IBOutlet weak var myWebView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
//define url
let url = NSURL (string: "http://www.my-url.com")
//request
let req = NSURLRequest(url: url as! URL)
//load request into the webview
myWebview(req as URLRequest) //error happens here :
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
谢谢!
【问题讨论】:
-
谢谢@Anbu.Karthik!它的工作!我不知道为什么,但它肯定有效!
标签: ios swift xcode uiviewcontroller uiwebview