0
我的UIWebView不会加载,我非常困惑。为什么.Webview在几个星期前工作。它所链接的网站得到更新。但由于某种原因,现在我发送给它的任何链接都不起作用。我试图清除缓存。我有点失落,为什么这不会出现。我的手机上的互联网工作正常。故事板中的所有内容都正确连接。Swift中的UIWebView问题
活动指标保持旋转。而我的警报是从应该发生的didFailLoadWithError出现的,但是找出为什么它不会连接会很好。任何帮助都会很棒,谢谢。
class CommunityViewController: UIViewController, UIWebViewDelegate {
@IBOutlet weak var activityIndicator: UIActivityIndicatorView!
@IBOutlet weak var communityWeb: UIWebView!
var refreshControl:UIRefreshControl!
let url = "http://www.google.com"
override func viewWillAppear(animated: Bool) {
NSURLCache.sharedURLCache().removeAllCachedResponses()
NSURLCache.sharedURLCache().diskCapacity = 0
NSURLCache.sharedURLCache().memoryCapacity = 0
}
override func viewDidLoad() {
super.viewDidLoad()
self.communityWeb.delegate = self
let requestURL = NSURL(string:url)
let request = NSURLRequest(URL: requestURL!, cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData,
timeoutInterval: 3.0)
communityWeb.loadRequest(request)
self.refreshControl = UIRefreshControl()
self.refreshControl.attributedTitle = NSAttributedString(string: "")
self.refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
self.communityWeb.scrollView.addSubview(refreshControl)
}
func refresh(sender:AnyObject)
{
let requestURL = NSURL(string:url)
let request = NSURLRequest(URL: requestURL!)
communityWeb.loadRequest(request)
refreshControl.endRefreshing()
}
func webViewDidStartLoad(webView: UIWebView) // here show your indicator
{
self.activityIndicator.startAnimating()
}
func webViewDidFinishLoad(webView: UIWebView) {
self.activityIndicator.stopAnimating()
self.activityIndicator.hidesWhenStopped = true
self.communityWeb.scrollView.contentSize.width = self.communityWeb.frame.size.width
}
func webView(webView: UIWebView, didFailLoadWithError error: NSError?) {
let alertView = SIAlertView(title: "Internet Connection", andMessage: "Connect to the internet to receive latest updates from the Community")
alertView.addButtonWithTitle("OK", type: SIAlertViewButtonType.Default, handler:
{alertView in
NSLog("pressed")
})
alertView.transitionStyle = SIAlertViewTransitionStyle.Fade
alertView.show()
}
苹果除了那个拥有NSAllowsArbitraryLoads的PList?在论坛阅读我得到了混合的答案。 – MangoCode