I'm using PageMenu through Cocoapods which has a Base ViewController and as subviews it has PFQueryTableViewController's, each one as one page.
The problem is that when the app starts and shows the first PFQueryTVC (as a subview) it doesn't show results if there are query.whereKey(...) functions inside queryForTable. It doesn't crash.
I've also noticed that viewWillAppear and viewDidAppear do not get called as well, but if I go to another page and then come back, the queryForTable does work, as well as viewWillAppear and viewDidAppear.
Here is part of my code:
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
}
When I go to another page and then come back, the queryForTable does work, as well as viewWillAppear and viewDidAppear.