我通過Cocoapods使用PageMenu,它有一個基本ViewController和子視圖PFQueryTableViewController的,每一個作爲一個頁面。queryForTable viewDidAppear,viewWillAppear等不與子視圖
問題是,當應用程序啓動並顯示第一個PFQueryTVC(作爲子視圖)時,如果queryForTable中存在query.whereKey(...)函數,則它不顯示結果。它不會崩潰。
我也注意到viewWillAppear和viewDidAppear不會被調用,但如果我去另一個頁面,然後回來,queryForTable確實工作,以及viewWillAppear和viewDidAppear。
這裏是我的代碼部分:
var city : String = "dallas"
class CouponsTableViewController: PFQueryTableViewController, DisplayAlert {
override init(style: UITableViewStyle, className: String?) {
super.init(style: style, className: className)
parseClassName = "Coupons"
pullToRefreshEnabled = true
paginationEnabled = true
objectsPerPage = 25
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
parseClassName = "Coupons"
pullToRefreshEnabled = true
paginationEnabled = true
objectsPerPage = 25
}
override func queryForTable() -> PFQuery {
let subquery = PFQuery(className: self.parseClassName!)
subquery.whereKey("city", equalTo: city) // this shows no results
subquery.whereKey("location", nearGeoPoint: userLocation)
let subquery2 = PFQuery(className: self.parseClassName!)
subquery2.whereKey("city", equalTo: "all") // this shows no results
subquery2.whereKey("location", nearGeoPoint: userLocation)
let query = PFQuery.orQueryWithSubqueries([subquery, subquery2])
// If Pull To Refresh is enabled, query against the network by default.
if self.pullToRefreshEnabled {
query.cachePolicy = .NetworkOnly
}
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if self.objects!.count == 0 {
query.cachePolicy = .CacheThenNetwork
}
return query
}
當我去到另一個網頁,然後再回來時,queryForTable沒有工作,以及viewWillAppear中和viewDidAppear。