gpt4 book ai didi

ios - Tableview 不显示数据

转载 作者:行者123 更新时间:2023-11-28 07:51:27 24 4
gpt4 key购买 nike

SecondVC.swift
这是 tableview 和 slider View 的代码文件,但输出中缺少 tableview 数据。请帮我解决这个问题。
代码看起来很完美,但单元格仍未显示从数据库中获取的内容。
正在显示单元格,但未显示任何内容实际上,显示的单元格数不等于 fields.count

O/p + Main.storyboard

File Hierarchy

import UIKit
import FirebaseAuth
import FirebaseDatabase

class SecondVC: UIViewController,UITableViewDelegate,UITableViewDataSource{

@IBOutlet weak var tableview: UITableView!
@IBOutlet weak var blurView: UIVisualEffectView!
@IBOutlet weak var sideView: UIView!
@IBOutlet weak var viewConstraint: NSLayoutConstraint!

var field = [Fields]()

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

func tableView(_ tableView: UITableView, cellForRowAt indexPath:
IndexPath) -> UITableViewCell {
let cell = tableview.dequeueReusableCell(withIdentifier:"SecondVCcell")
cell?.selectionStyle = .none
cell?.textLabel?.text = field[indexPath.row].Field_fieldname
cell?.detailTextLabel?.text = field[indexPath.row].Field_fieldvalue
return cell!
}

var name : String?
override func viewDidLoad() {
super.viewDidLoad()

tableview.delegate = self
tableview.dataSource = self
blurView.layer.cornerRadius = 15
sideView.layer.shadowColor = UIColor.black.cgColor
sideView.layer.shadowOpacity = 0.8
sideView.layer.shadowOffset = CGSize(width : 5, height : 0)

viewConstraint.constant = -175
loadData()
}

func loadData()
{
let userID = Auth.auth().currentUser!.uid


if let dict = snapshot.value as? [String : Any]
{
let fieldV = dict["fieldN"] as! String
let fields = Fields(fn: snapshot.key , fv: fieldV)
self.field.append(fields)
self.tableview.reloadData()
}
}

@IBAction func PanGestureTriggered(_ sender: UIPanGestureRecognizer) {



if sender.state == .began || sender.state == .changed
{
let translate = sender.translation(in: self.view).x
if translate > 0
{
if viewConstraint.constant < 20
{
UIView.animate(withDuration: 0.2, animations: {
self.viewConstraint.constant += translate/10
self.view.layoutIfNeeded()
})
}
}
else
{
if viewConstraint.constant > -175
{
UIView.animate(withDuration: 0.2, animations: {
self.viewConstraint.constant += translate / 10
self.view.layoutIfNeeded()
})
}
}
}
else if sender.state == .ended
{
if viewConstraint.constant < -100
{
UIView.animate(withDuration: 0.2, animations: {
self.viewConstraint.constant = -175
self.view.layoutIfNeeded()
}

)}
else
{
UIView.animate(withDuration: 0.2, animations: {
self.viewConstraint.constant = 0
self.view.layoutIfNeeded()
}
)}


}
}
@IBAction func SignOutTapped(_ sender: Any) {
let firebaseAuth = Auth.auth()
if firebaseAuth.currentUser != nil
{
do {
try firebaseAuth.signOut()
} catch let signOutError as NSError {
print ("Error signing out: %@", signOutError)
}
}
if firebaseAuth.currentUser == nil
{
let loginVC = UIStoryboard(name: "Main",
bundle:nil).instantiateViewController(withIdentifier: "Login") as!
ViewController
self.present(loginVC, animated: true, completion: nil)
}
}
@IBAction func HomeButtonTapped(_ sender: UIButton) {
UIView.animate(withDuration: 0.2, animations: {
self.viewConstraint.constant = -175
self.view.layoutIfNeeded()
}
)}
@IBAction func unwindSegue(_ sender: UIStoryboardSegue)
{
}
}

最佳答案

如果您使用的是自定义表格单元格,那么您还没有注册 Nib。

tableView.register(UINib(nibName: "", bundle: nil), forCellWithReuseIdentifier:"")

如果您使用的是原型(prototype)单元格,那么您必须获取字段数组计数 0

关于ios - Tableview 不显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49553168/

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