技术:XCode6,iOS 8.2,Swift
加载视图时,我添加了一张图片:
override func viewDidLoad() {
super.viewDidLoad()
webView.delegate = self
self.navigationController?.toolbarHidden = false;
openLoadingPopup()
if browserHistory.count < 1 {
backButton.enabled = false
}
let imageName = UIImage(named: "image.png")
let imageview = UIImageView(image: imageName)
imageview.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)
self.view.addSubview(imageview)
}
我想在这里删除该图像(如果可能的话)。最好的方法吗?
func webViewDidFinishLoad(webView: UIWebView) {
UIApplication.sharedApplication()
. networkActivityIndicatorVisible = false
closeLoadingPopup()
if cacheURL {
++browserHistoryIndex
browserHistory.insert(webView.request!.URL, atIndex: browserHistoryIndex)
backButton.enabled = browserHistoryIndex != 0
//forwardButton.enabled = browserHistoryIndex != browserHistory.count - 1
}
if webView.request!.URL == lastURL {
cacheURL = true
}
}
答案 0 :(得分:1)
使imageView成为属性而不是局部变量,并在webViewDidFinishLoad方法中使用imageView.removeFromSuperview()。