我试图学习IOS编程,真正的第一步,并且无法通过完整的类代码找到我的问题的Swift示例。 正在加载网页,但我从未收到回复。 它显然是"扩展"部分,我可能不需要代表
import UIKit
class VkLoginViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!
var delegate:UIWebViewDelegate!
override func viewDidLoad() {
super.viewDidLoad()
let link = String.localizedStringWithFormat("http://api.vk.com/oauth/authorize?client_id=%@&scope=email,photos,offline&redirect_uri=http://api.vk.com/blank.html&display=touch&response_type=token", Setup.VK_AUTH_SCHEME)
NSLog(link)
delegate = self
UIWebView.loadRequest(webView)(NSURLRequest(URL: NSURL(string: link)!))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension VkLoginViewController : UIWebViewDelegate{
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
let str = request.URL?.absoluteString
NSLog(str!)
return true
}
}
我从来没有得到第二条NSLog的消息
答案 0 :(得分:3)
将代码修改为
class VkLoginViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let link = String.localizedStringWithFormat("http://api.vk.com/oauth/authorize?client_id=%@&scope=email,photos,offline&redirect_uri=http://api.vk.com/blank.html&display=touch&response_type=token", Setup.VK_AUTH_SCHEME)
NSLog(link)
webView.delegate = self
webView.loadRequest(webView)(NSURLRequest(URL: NSURL(string: link)!))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension VkLoginViewController : UIWebViewDelegate{
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
let str = request.URL?.absoluteString
NSLog(str!)
return true
}
}
希望这个帮助