- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Stack Overflow 的新手,所以请保持温柔!
我正在设计一个应用程序,它从 firebase 检索对象并在 firebase 中显示它们。
我在这里配置firebase:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FIRApp.configure()
FIRDatabase.database().persistenceEnabled = true
// Override point for customization after application launch.
return true
}
但是,我发现当我运行该应用程序时,我只是得到一个空白的白屏。经过一番调试后,我意识到这是因为未到达 TableView (cellForRowAt indexPath: IndexPath) 代码块:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell", for: indexPath)
let BUCSItem = items[indexPath.row]
cell.textLabel?.text = BUCSItem.name
print("should show bucs")
return cell
}
我有其他所需的 tableView 方法:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}
这是我的 viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
let ref = FIRDatabase.database().reference(withPath: "BUCS-items")
tableView.allowsMultipleSelectionDuringEditing = false
ref.queryOrdered(byChild: "BUCSgoals").observe(.value, with: { snapshot in
var newItems: [BUCSItem] = []
for child in snapshot.children {
if let snapshot = child as? FIRDataSnapshot,
let BUCSItem = BUCSItem(snapshot: snapshot) {
newItems.append(BUCSItem)
}
}
self.items = newItems
self.tableView.reloadData()
})
}
但这就是奇怪的部分。当我断开互联网连接时,它工作得很好,并且项目按预期显示在表格中。仅当连接到互联网时它们才不会显示。
这是断开连接时的样子:连接后,其相同,但名称未出现在表中。
任何帮助将不胜感激!
最佳答案
我认为这是一个快速更新转换
ref.queryOrdered(byChild: "BUCSgoals").observe(.value
至
ref.queryOrdered(byChild: "BUCSgoals").observeSingleEvent(.value
关于swift - 尝试从 Firebase 检索数据时未调用 tableView(_ tableView : UITableView, cellForRowAt indexPath: IndexPath) 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51480178/
当我尝试运行代码时,cellForRowAtIndexPath 函数由于某种原因无法运行。 numberOfSections 函数运行良好。我认为这是 dataSource/delegate 函数或单
我对使用 cellForRowAt 执行代码的顺序有疑问 这是我的 cellForRowAt 函数 func tableView(_ tableView: UITableView, cellForRo
我需要检测 UITableViewController 中的按钮是否被点击 override func tableView(_ tableView: UITableView, cellForRowAt
我创建了两个类 NumberTableViewCell 和 YesNoTableViewCell,它们的类型均为 UITableViewCell。它们“附加”了动态原型(prototype)(如果我说
我的程序构建如下: 我有一个 UIViewController SingleEventViewController 来布局和处理事件的数据。它的元素之一是 UIView TeilnehmerTable
根据下面的代码,我第一次运行应用程序。前 3 行工作正常。但是当我上下滚动时。一些线路也会改变。当我做更多的上下它更改为其他行 我该如何解决这个问题 func tableView(_ tabl
我在 UITableViewController 中创建 TableView 时遇到问题。行数返回非零数,高度在 Storyboard 中设置。但是 cellForRowAt永远不会被调用。 这是代码
这个问题让我疯狂了 3 天。我创建了一个自定义单元类: class TransitoPalinaTableViewCell: UITableViewCell { @IBOutlet weak var
我认为我很接近,但似乎让自己感到困惑,因为我可以访问所有数据,但无法使其正常运行。 我正在尝试在表格 View 的表格中显示其各自公司(部门)下的员工列表。 我的 CoreData 在存储值和关系方面
你能帮我找到一个解决方案,而不是一次又一次地复制相同的代码吗?现在我有了这段代码 func tableView(_ tableView: UITableView, cellForRowAt i
我在使 cellForRowAt 工作时遇到问题,但不幸的是我的应用程序在编译后仍然是空白的。我正在使用 Xcode 8.3 beta 3。 import UIKit class myCell: UI
我是 swift 和 UITableView 的新手,我正在从请求中获取数据,并试图在表格 View 上显示结果。我得到的数据很好,但我的表格 View 不滚动。我知道这个问题有很多问题,但我看到其他
我试图在按下 UITabelViewCell 时获得不同的标签文本,但我无法让它工作。 completed 的默认值为 false,触摸时应为 true,然后应更改标签。在 didSelectRowA
这个问题在这里已经有了答案: How to get the indexpath.row when an element is activated? (20 个答案) 关闭 5 年前。 我想访问 ce
我有一个 ChatViewController 和聊天消息。我使用 Storyboard 约束和标识符初始化消息气泡的布局,以通过代码更改它们: func tableView(_ tableView:
我需要将表格滚动到底部。当我在 viewwilAppear 中编写滚动表格的代码时,它不起作用,但是当我在 viewDidAppear 中编写相同的代码时,它可以工作,但用户会看到滚动。我不想看到用户
我有一个问题,numberOfRowsInSection 和 cellForRowAt 函数不返回值。我需要将名称和价格从 coincap.io/front API 返回到 tableView 中。我
我正在尝试拥有 UITableView (主要)其中包含另一个 UITableView (次要)在每个单元格中。主要和次要 TableView 都有自己的数据源对象类,MajorDatasource
我是一名入门级 swift 开发人员,我正在个人应用程序中工作,但我的“tableViewController”遇到了问题。 我有一个第一个表格 View ,我从 API 中获取一些事件,然后我想做的
我有一个显示购物 list 名称的 TableView Controller 。这些购物 list 是通过购物 list 类创建的,它让我可以指定购物 list 的名称和其中的项目。此 TableVi
我是一名优秀的程序员,十分优秀!