2016-05-04 57 views
1

我通過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。

回答

0

你說:

的問題是,當應用程序啓動並顯示第一PFQueryTVC (作爲一個子視圖),它並不顯示的結果,如果有 query.whereKey(...)函數在queryForTable中。它不會崩潰。

但應該呈現視圖控制器而不是顯示。如果你想讓一個視圖控制器包含並呈現另一個視圖控制器,有機制可以做到這一點,但它不像獲取視圖並將其添加爲子視圖那樣簡單。見ViewControllerContainment

然而,實現代碼如下不需要屬於的tableview控制器,它可以添加到任何視圖控制器提供您設置數據源(在很多情況下,你將要設置委託太) 。

相關問題