gpt4 book ai didi

ios - 使用 Parse 数据库填充表

转载 作者:行者123 更新时间:2023-11-30 13:27:36 25 4
gpt4 key购买 nike

我正在开发一个 iOS 应用程序,它从 Parse 数据库中提取数据来填充 TableView 。我可以从数据库获取数据并打印到日志中,但是当我尝试使用数据填充表单元格时,它不起作用。每次 table 都是空的,我不明白为什么。有什么想法吗?

import UIKit
import Parse

var promoNum = -1

class TableViewController: UITableViewController, CLLocationManagerDelegate {

var titles = [String]()

override func viewDidLoad() {
super.viewDidLoad()

var getPromosQuery = PFQuery(className: "Promotions")
getPromosQuery.whereKey("zip", equalTo: "85281")
getPromosQuery.findObjectsInBackgroundWithBlock { (objects, error) in
if let objects = objects {

for object in objects {

self.titles.append(object["title"] as! String)

}
}
}
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return titles.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let promoCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! Cell

promoCell.promotionTitle.text = titles[indexPath.row]

return promoCell
}

override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
promoNum = indexPath.row
return indexPath
}

}

最佳答案

修好了!我只需要在 self.titles.append(object["title"] as! String) 之后添加 self.tableView.reloadData() 即可。

关于ios - 使用 Parse 数据库填充表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36974705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com