gpt4 book ai didi

ios - 如何在 Xcode 11 中制作连接到 Firebase 的搜索栏页面

转载 作者:行者123 更新时间:2023-12-01 21:58:15 25 4
gpt4 key购买 nike

我正在尝试在我的应用程序中实现一个带有表格 View 的搜索栏,以搜索 Firebase 存储中的数据。我在做这个的时候遇到了很多错误。我的两个错误有 Use of unresolved identifier 'cell' , 两个有 Use of unresolved identifier 'inSearchMode'接下来的两个是Value of type 'Storage' has no subscriptsValue of type 'Storage' has no member 'filter' .一段时间以来,我一直试图找出这些错误。任何帮助将不胜感激!谢谢你。

ps错误显示为注释:

import Foundation

导入 Firebase

类 SearchBarViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var searchBar: UISearchBar!

var data = Storage.storage()
var filteredData = [String]()
var isSearching = false

override func viewDidLoad() {
super.viewDidLoad()

tableView.delegate = self
tableView.dataSource = self
searchBar.delegate = self
searchBar.returnKeyType = UIReturnKeyType.done
}

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

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if isSearching {
return filteredData.count
}
return data.accessibilityElementCount() //Might be a problem
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView.dequeueReusableCell(withIdentifier: "dataCell", for: indexPath) is DataCell {

let text: String!

if isSearching {
text = filteredData[indexPath.row]
} else {

text = data[indexPath.row] //Value of type 'Storage' has no subscripts
}
cell.configureCell(data: text) //Use of unresolved identifier 'cell'

return cell //Use of unresolved identifier 'cell'


} else {

return UITableViewCell()

}
}

func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
if searchBar.text == nil || searchBar.text == "" {

inSearchMode = false //Use of unresolved identifier 'inSearchMode'

view.endEditing(true)

tableView.reloadData()
} else {
inSearchMode = true //Use of unresolved identifier 'inSearchMode'

filteredData = data.filter({$0 == searchBar.text!}) //Value of type 'Storage' has no member 'filter'

tableView.reloadData()
}
}

}

最佳答案

错误 Use of unresolved identifier 'cell'造成的,因为您实际上并没有创建任何单元格,您只需键入 check is DataCell .为了解决这个问题,这条线应该是

if let cell = tableView.dequeueReusableCell(withIdentifier: "dataCell", for: indexPath) as? DataCell { 
}

对于第二个问题,访问 data[indexPath.row] ,由于我不知道它是什么数据类型,所以不能给你答案。

第三期, Use of unresolved identifier 'inSearchMode' ,没有为它声明变量。所以是意料之中的。 isSearching可能是您应该用它替换的那个。

关于ios - 如何在 Xcode 11 中制作连接到 Firebase 的搜索栏页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60943098/

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