TableView不打印任何单元格(swift)

时间:2017-05-07 18:26:46

标签: swift firebase firebase-realtime-database firebase-authentication

我试图将当前从firebase数据库中提取的简单值显示为TableView。我得到的问题是单元格当前没有填充任何东西。我已经放入print语句只是为了确保数组不是空的,而不是。我使用以下代码:

    class DisplayTransactions: UITableViewController {

    var ref = FIRDatabase.database().reference()

    //gets current firebase users
    var userC = FIRAuth.auth()?.currentUser
    var pubCount: Int!
    var anArray = [String] ()

    override func viewDidLoad() {
        super.viewDidLoad()
        var transRef = FIRDatabase.database().reference().child("Users").child((userC?.uid)!).child("PaymentTransactions")

        //for Deposit children
        transRef.child("Deposit").observeSingleEventOfType(.Value, withBlock: { (snapshot) in
            //creates enumerator of the snapshot children for
            let enumerator = snapshot.children
            while let rest = enumerator.nextObject() as? FIRDataSnapshot {
                self.anArray.append(String(rest.value))

                //printing the rest.value to make sure there are children to iterate through
                print(rest.value)
            }
        })
        //for Withdrawl children
        transRef.child("Withdraw").observeSingleEventOfType(.Value, withBlock: { (snapshot) in
            //creates enumerator of the snapshot children for
            let enumerator = snapshot.children
            while let rest = enumerator.nextObject() as? FIRDataSnapshot {
                self.anArray.append(String(rest.value))

                //printing the rest.value to make sure there are children to iterate through
                print(rest.value)
            }
        })
        print(anArray)
    }

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

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: .Subtitle, reuseIdentifier: "cellID")

        cell.textLabel?.text = anArray[indexPath.row]
        print(anArray[indexPath.row])

        return cell
    }
}

1 个答案:

答案 0 :(得分:1)

在填写数据源后,您似乎没有重新加载UITableView。 每次更改数组内容时都需要这样做。

if(string.Compare(w.Trim(), a.word, true) == 0)