【发布时间】:2015-10-02 21:34:58
【问题描述】:
我能够从 Parse Core 检索我的“项目”对象,然后将“项目名称”值返回给我并打印到日志中。我认为这些值会更新我的 productNames 数组,然后将其显示在我的 TableView 中。我的原型 tableview 单元格在 DealCell 类中定义,带有图像和标签。当我运行应用程序时,我的 tableView 是空的。我错过了什么?
我的 TableView 的类:
var productIds = [String]()
var productNames = [String]()
override func viewDidLoad() {
super.viewDidLoad()
self.productIds.removeAll(keepCapacity: true)
self.productNames.removeAll(keepCapacity: true)
// Ask for the current user's personal list of saved PFObject IDs.
let Ids = PFUser.currentUser()?.objectForKey("accepted") as! NSArray
print(Ids)
// Requesting the Project objects based on the Ids retrieved.
let projectRetrieval = PFQuery(className: "project")
projectRetrieval.whereKey("objectId", containedIn: Ids as [AnyObject])
projectRetrieval.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if let objects = objects {
for object in objects {
//Append the productNames array with retrieved projectnames
self.productNames.append(object["projectname"] as! String)
// This line successfully prints the array of product Names retrieved.
print("Projectnames: \(self.productNames)")
}
}
})
}
// Number of Rows
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.productNames.count;
}
// Assign the productNames to the labels in each cell.
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("dealcell", forIndexPath: indexPath) as! DealCell
cell.productName.text = self.productNames[indexPath.row]
return cell
}
我的打印输出很奇怪,看起来像这样,但它正在成功获取项目名称:
Projectnames: ["Personal Drone"]
Projectnames: ["Personal Drone", "Prosthetic Limb Patent"]
【问题讨论】:
标签: swift uitableview parse-platform