将相关显示方法封装在UIViewController的extension中,方便全局调用
显示错误信息页面,网络请求错误时调用此方法
public func showErrorView(scrollView:UIScrollView) {
let imageView = ErrorView() //ErrorView为自定义的错误提示框
imageView.frame = scrollView.bounds
imageView.tag = 999
scrollView.addSubview(imageView)
}
再次加载成功时记得移除相关页面
func removeErrorView(scrollView:UIScrollView) {
for tmpView in scrollView.subviews {
if let imageView = tmpView as? ErrorView,imageView.tag == 999 {
tmpView.removeFromSuperview()
}
}
}
显示和移除空白页,网络请求数据为空时调用此方法,count为0时显示,否则移除空白页
public func showNotDataView(scrollView:UIScrollView,count:Int) {
if count == 0 {
let notDataView = NotUploadBookView() //NotUploadBookView为自定义的空白页
notDataView.frame = scrollView.bounds
notDataView.tag = 999
scrollView.addSubview(notDataView)
}else{
for tmpView in scrollView.subviews {
if let notDataView = tmpView as? NotUploadBookView,notDataView.tag == 999 {
notDataView.removeFromSuperview()
}
}
}
}