gpt4 book ai didi

swift - Swift 中的 PFQueryTableViewController 不加载数据

转载 作者:行者123 更新时间:2023-11-30 10:18:40 26 4
gpt4 key购买 nike

我正在创建一个应用程序,将数据从 Parse 加载到 UITableView 中。我使用了一些代码,似乎可以将检索到的数据加载到表中的单元格中,但它有问题,我做了一些研究并找到了 PFQueryTableViewController。这似乎是我问题的解决方案,但所有文档都是 Objective-C 语言(我没有任何编码经验),而且我找不到关于如何在 Swift 中使用此类的教程。有一些片段讨论了如何初始化它,但没有真正介绍如何在 Swift 中设置它。我尝试浏览 Obj-C 文档并自己在 Swift 中设置它,但我似乎无法正确设置,并且非常感谢一些帮助。有没有人有建议的资源或有人设置了一个资源并可以逐步说明如何在 Swift 中执行此操作?

编辑:我找到了一些资源并尝试对其进行设置, TableView 加载,但没有任何内容加载到单元格中,我不确定。我将把代码留在下面。注释掉的部分与我的代码无关,但仅供引用。有关表格未加载原因的任何进一步帮助都会有所帮助!

class MyCookbookVC : PFQueryTableViewController {

override init!(style: UITableViewStyle, className: String!) {
super.init(style: style, className: className)
textKey = "Name"
pullToRefreshEnabled = true
paginationEnabled = true
objectsPerPage = 25
}

required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

override func viewDidLoad() {

tableView.reloadData()

}

override func queryForTable() -> PFQuery! {
let query = PFUser.query()
query.whereKey("CreatedBy", equalTo: PFUser.currentUser())
query.orderByAscending("Name")

//if network cannot find any data, go to cached (local disk data)
if (self.objects.count == 0){
query.cachePolicy = kPFCachePolicyCacheThenNetwork
}

return query
}

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell! {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as PFTableViewCell
cell.textLabel?.text = object["Name"] as? String

/*if let profileImage = object["profileImage"] as? PFFile {
cell.imageView.file = profileImage
}
else {
cell.imageView.image = kProfileDefaultProfileImage
}
cell.imageView.layer.cornerRadius = cell.imageView.frame.size.width / 2;
cell.imageView.clipsToBounds = true
cell.imageView.layer.borderWidth = 3.0
cell.imageView.layer.borderColor = UIColor.whiteColor().CGColor */


/* cell.textLabel?.font = UIFont(name: kStandardFontName, size: kStandardFontSize)
cell.textLabel?.textColor = UIColor.whiteColor()
cell.backgroundColor = kbackgroundColor */

return cell
}
}

最佳答案

您的查询正在查询 PFUser,而它应该查询您的“Recipe”类。更改此行

let query = PFUser.query()

let query = PFQuery.queryWithClassName("Recipe")

关于swift - Swift 中的 PFQueryTableViewController 不加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28610050/

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