我有一个带UIRefreshControl和UISearchBar的UITableView。启动应用程序时,只有第一次,当我关注搜索栏时,刷新控件才会打开并保持打开状态。
出现这种情况的原因是什么?
以下是刷新代码:
func refresh(sender:AnyObject) {
manager = OneShotLocationManager()
self.manager!.fetchWithCompletion {location, error in
// fetch location or an error
if let loc = location {
print(loc)
} else if let err = error {
print(err.localizedDescription)
}
self.manager = nil
self.loadRestaurant(location)
}
}
以下是搜索代码:
func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
if (searchBar.text!.isEmpty) {
isSearching = false
} else {
isSearching = true
let searchText = searchBar.text!
let predicate = NSPredicate(format: "name contains[c] %@", searchText)
filteredRestaurants = restaurants.filter { predicate.evaluateWithObject($0) }
}
tableView.reloadData()
}