2015-08-22 66 views
1

嗨,大家好,我試圖打印我的查詢其在香港專業教育學院創建解析,在這裏它是 能正常工作和做什麼,我需要它查詢解析,如何在Swift中的tableView單元格中打印數據?

//store my currentLocations here 
var locations : [PFObject] = []  

PFGeoPoint.geoPointForCurrentLocationInBackground { (geoPoint: 
PFGeoPoint?, error: NSError?) -> Void in 

     if geoPoint != nil { 

      var geoPointLon = geoPoint?.longitude 
      var geoPonitLan = geoPoint?.latitude 
      var currentLocation = PFGeoPoint(latitude: geoPonitLan!, longitude: geoPointLon!) 

      var query = PFQuery(className: "User") 
      query.whereKey("currentLocation", nearGeoPoint: currentLocation, withinKilometers: 5.0) 
      query.findObjectsInBackgroundWithBlock({ (objects: [AnyObject]?, error: NSError?) -> Void in 

       if let myObject = objects as? [PFObject] { 

        for objects in myObject { 

         self.locations.append(objects) 

        } 

       } 

       self.tableView.reloadData() 


      }) 

     } 

    } 

這是我的tableview細胞和行

func tableView(tableView: UITableView, numberOfRowsInSection section: 
Int) -> Int { 

    return self.locations.count 


} 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let cell = UITableViewCell() 

    cell.textLabel?.text = "test" 

    return cell 

} 

當運行我的應用程序「測試」確實打印正確的條目數,所以我知道我的查詢正在工作。

我的問題是如何打印我的課堂「用戶」,在Parse內名爲「currentLocation」的列的實際位置?

如果您需要任何其他信息只是讓我知道感謝

+0

您正在錯誤地創建您的單元格。 –

+0

嘿,yep我知道,這是一個測試單元打印查詢的數量,需要正確的版本顯示什麼數據庫 –

回答

1

假設你的「currentLocation」列是一個字符串,這就是你怎麼把它找回來。

如果它不是字符串,那麼您可能需要將其轉換。

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let cell = UITableViewCell() 

    cell.textLabel?.text = self.locations["currentLocation"] 

    return cell 

} 
+0

試圖通過轉換?字符串,但得到一個錯誤,這個列是一個PFObject幷包含geoPoint位置,任何想法? –

相關問題