我正在構建和應用程序,它使用解析將對象保存在本地數據存儲中。然後,我運行一個查詢來檢索本地數據存儲中的對象,並且它工作正常。但是,我想抓取對象及其中的內容,並根據存儲在解析本地數據存儲對象中的項目在表視圖單元中設置一些標籤。例如,我使用「objectID」,「name」,「date」,「location」等屬性創建對象。我想要做的是在主屏幕上顯示一個表格視圖,顯示名稱,日期,位置等。每個單元中標籤中保存在本地數據存儲中的每個項目的數量。Swift解析 - 本地數據存儲和在桌面視圖中顯示對象
我知道,即時通訊正確保存它:
// parse location object
let parseLighthouse = PFObject(className: "ParseLighthouse")
parseLighthouse.setObject(PFUser.currentUser()!, forKey: "User")
parseLighthouse["Name"] = self.placeTitle.text
parseLighthouse["Note"] = self.placeNote.text
parseLighthouse["Locality"] = self.placeDisplay.text!
parseLighthouse["Latt"] = self.map.region.center.latitude
parseLighthouse["Longi"] = self.map.region.center.longitude
parseLighthouse["LattDelta"] = 0.5
parseLighthouse["LongiDelta"] = 0.5
parseLighthouse["Date"] = dateInFormat
parseLighthouse.pinInBackground()
parseLighthouse.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
println("Object has been saved. ID = \(parseLighthouse.objectId)")
}
,當我運行查詢,即時通訊能夠通過運行的println(object.objectForKey( 「名稱」))來訪問屬性
func performQuery() {
let query = PFQuery(className: "ParseLighthouse")
query.fromLocalDatastore()
query.whereKey("User", equalTo: PFUser.currentUser()!)
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if error == nil {
// The find succeeded.
println("Successfully retrieved \(objects!.count) lighthouses.")
// Do something with the found objects
if let light = objects as? [PFObject] {
for object in light {
println(object.objectId)
println(object.objectForKey("Name"))
}
}
} else {
// Log details of the failure
println("Error: \(error!) \(error!.userInfo!)")
}
}
,因爲當運行查詢時,我按照預期返回對象ID和名稱。
成功檢索到2座燈塔。 可選(「A3OROVAMIj」) 可選(高興) 可選(「bbyqPZDg8W」) 可選(日期測試)
什麼,我想這樣做是解析對象的本地數據存儲中搶名稱字段,以及是表視圖控制器中單元格上標籤的名稱。
我不知道如何訪問該對象的信息,並正確設置標籤。
沒有人知道這是可能的嗎?
你有你的tableView準備好了嗎?那麼你可以開始訪問解析數據並在其中顯示數據?或者你問如何使用parse.com數據做tableView? –
你是說你得到一個叫做「object」的對象,但它實際上是一個你正在使用的自定義類對象?你有沒有嘗試將它投射到實際的課程並以這種方式訪問屬性?在Objective C中,你可以像這樣訪問name屬性:((PFUser *)object).name,儘管我不確定swift是什麼。 –
所以你查詢功能是否正常工作,你應該想要獲得這些信息,然後加載你的tableview中的所有單元格......對嗎? – Lamar