gpt4 book ai didi

swift - 从 Parse 加载数据到 TableView

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

大家好,我创建了一个函数,下面将项目保存到 tweetData :[PFObject] 数组

 func loadData() {

//all current data to be displayed, adding data 1 by 1 remove whats there on reloading
tweetData.removeAll()

//query database for all tweets, very important that whats in the classname here, is the
//same name as the class with Parse where these are being stored

let findTweets:PFQuery = PFQuery(className: "Tweets")

findTweets.findObjectsInBackgroundWithBlock { (objects:[PFObject]?, error: NSError?) -> Void in

if error == nil {

for object:PFObject in objects! {

self.tweetData.append(object)

}

//--very important!!! dont forget to reload table data otherwise you will return no results
self.tableView.reloadData()

} else {

print("nothing to load")

}

}

}

如何将其放入我的表格 View 中以显示数据?一直在挣扎并遇到各种错误。这是我的表格 View cellForRowAtIndexPath

 func tableView(tableView: UITableView, cellForRowAtIndexPath  

indexPath: NSIndexPath) -> UITableViewCell {

//use your custom table view cell here which is defined in another class

let cell:CellTableViewCellController = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CellTableViewCellController


//NEED TO LOAD MY DATA



return cell

//-----add load data function to viewDidAppear method


}

有人能帮我解决这个问题吗?谢谢

最佳答案

all sorted just used query.objectforkey


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

//use your custom table view cell here which is defined in another class

let cell:CellTableViewCellController = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CellTableViewCellController

let query = tweetData[indexPath.row]

cell.textLabel!.text = query.objectForKey("TweetContent") as? String

return cell

//-----add load data function to viewDidAppear method


}

关于swift - 从 Parse 加载数据到 TableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33721118/

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