1

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0

You say:

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.

but view controllers should be presented rather than shown. If you want one view controller to contain and present another there are mechanisms to do that but it isn't as simple as just getting the view and adding it as a subview. See View Controller Containment

However, a tableview does not need to belong to a tableview controller, it can be added to any view controller providing that you set a datasource (and in many cases you will want to set the delegate too).

Community
  • 1
  • 1
Joseph Lord
  • 6,446
  • 1
  • 28
  • 32