虽然我在viewDidLoad中编写了以下代码,但我无法在静态表视图的顶部显示活动指示器。
let activityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)
tableView.backgroundView = activityIndicatorView
tableView.separatorStyle = UITableViewCellSeparatorStyle.none
self.activityIndicatorView = activityIndicatorView
self.activityIndicatorView.isHidden = false
self.tableView.addSubview(activityIndicatorView)
self.activityIndicatorView.startAnimating()
答案 0 :(得分:2)
不是在UIActivityIndicatorView
中添加tableView
,而是将其添加到主视图中并调用主视图上的bringSubview(toFront:)
以将indicatorView
置于前面还没有设置indicatorView
集的原点位置。
self.activityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)
tableView.separatorStyle = UITableViewCellSeparatorStyle.none
self.activityIndicatorView.isHidden = false
//Add inside your view
self.view.addSubview(activityIndicatorView)
//Set activityIndicatorView origin in the screen
self.activityIndicatorView.center = self.view.center
//Try to bring activityIndicatorView to front
self.view.bringSubview(toFront: activityIndicatorView)
self.activityIndicatorView.startAnimating()
答案 1 :(得分:0)
您无法将子视图添加到tableview,请尝试在导航控制器视图中添加它。
喜欢:
self.view.superviewaddSubview(activityIndicatorView);
答案 2 :(得分:0)
如果你使用pull来刷新,那么实现这个代码:
var refreshControl: UIRefreshControl!
override func viewDidLoad() {
super.viewDidLoad()
refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
tableView.addSubview(refreshControl)
}
func refresh(sender:AnyObject) {
tableView.reloadData()
refreshControl.endRefreshing()
}