Table 1: User
Column: username, email, address
Table 2: Request
Column: item_wanted, username
Note: username in Table2 is a "pointer" that point to Table 1 (you must use pointer)
import UIKit
import Parse
import ParseUI
class TableViewController2: PFQueryTableViewController {
override func queryForTable() -> PFQuery {
var query = PFQuery(className: "Request")
query.includeKey("username")
return query
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as PFTableViewCell!
if cell == nil {
cell = PFTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
}
if let myrequester = object?["username"] as? PFObject
{
if let myusername = myrequester["username"] as? String
{
cell.textLabel?.text = myusername
}
}
if let mysubtitle = object?["item_wanted"] as? String
{
cell?.detailTextLabel?.text = mysubtitle
}
return cell
}
}
///////////////////////////////////////////////////////////////
Key Note 1: You must use query.includeKey("username"), this mean you want Parse to include all the data from the table "User" using the key "username"
Key Note 2: Since it is double layer, you query table "Request" then into table "User" , so you need to access the data double layer
if let myrequester = object?["username"] as? PFObject
{
if let myusername = myrequester["username"] as? String
{
cell.textLabel?.text = myusername
}
}
you access the object["username") to get to the table "User" then you need to do it one more time myusername = myrequester["username"]
hopefully I can help you in anyway, cheers
No comments:
Post a Comment