gpt4 book ai didi

ios - 数据服务错误未解决

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

我遇到的许多问题之一就是这个错误:

Type 'DataService' has no member 'dataService'

我一直在寻找,但找不到任何明确的信息。感谢您的帮助。我不确定问题是什么。我一开始以为服务已更改为数据库,但这也不正确,除非我完全错了。

import UIKit
import Firebase

class UserFeedTableViewController: UITableViewController {
let ref = Database.database().reference(withPath: "userpost-items")

var userpost = [UserPost]()

override func viewDidLoad() {
super.viewDidLoad()

// observeEventType is called whenever anything changes in the Firebase - new Jokes or Votes.
// It's also called here in viewDidLoad().
// It's always listening.

DataService.dataService.USERPOST_REF.observe(.value, with: { snapshot in
// The snapshot is a current look at our jokes data.
self.userposts = []

if let snapshots = snapshot?.children.allObjects as? [FDataSnapshot] {
for snap in snapshots {
// Make our jokes array for the tableView.

if let postDictionary = snap.value as? Dictionary<String, AnyObject> {
let key = snap.key
let userpost = UserPost(key: key!, dictionary: postDictionary)

// Items are returned chronologically, but it's more fun with the newest jokes first.

self.userpost.insert(userpost, at: 0)
}
}
}

// Be sure that the tableView updates when there is new data.

self.tableView.reloadData()
})
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return userpost.count
}

override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let userpost = self.userpost[indexPath.row]

// We are using a custom cell.
if let cell = tableView.dequeueReusableCell(withIdentifier: "UserPostCellTableViewCell") as? UserPostTableViewCell {
// Send the single user post to configureCell() in UserPostCellTableViewCell.
cell.configureCell(userpost: userpost)

return cell
} else {
return UserPostTableViewCell()
}
}
}

最佳答案

我发表了评论,但实际代码将更清楚地阐明我建议的模式。还有 100 种其他方法可以实现此目的。 (注:Swift 4、Firebase 4)

class UserFeedTableViewController: UITableViewController {
var ref: DatabaseReference!

var userpost = [UserPost]()

override func viewDidLoad() {
super.viewDidLoad()

self.ref = Database.database().reference()
}

func loadPosts() {
let postRef = self.ref.child("posts")
postRef.observe(.value, with: { snapshot in
self.userposts = []
...
}

关于ios - 数据服务错误未解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51216529/

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