简体   繁体   English

我如何使用swift3从Firebase数据库中存储具有多个字符串的对象

[英]How can I store object has a multiple strings from firebase database using swift3

I have object named myArray in firebase database structure and it has a multiple lines of strings as [a , b and c ] like this 我在firebase数据库结构中有一个名为myArray的对象,它具有像[a,b和c]这样的多行字符串 我的数据库结构 how can I display this object in my Table View ,When I run it its coming in My Debug like this 如何在表格视图中显示该对象,当我运行该对象时,它会像这样在My Debug中显示 我的调试 but its not appears in my simulator its appease like this 但它没有出现在我的模拟器中 我的模拟器 ,I am using swift 3 ,我正在使用swift 3

This is My Code : 这是我的代码:

import UIKit
import Firebase

class TestTable: UITableViewController {

var arrayList = [test]()

var Ref = FIRDatabaseReference()


override func viewDidLoad() {
    super.viewDidLoad()

    Ref=FIRDatabase.database().reference()

    Ref.child("Users").child("Test").observe(.childAdded ,with: { (snapshot) in

        if  let User = snapshot.value as? [String : AnyObject]{

            let Add = test()

            Add.setValuesForKeys(User)

            self.arrayList.append(Add)


            print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\(snapshot.value)")

            self.tableView.reloadData()

        }

    })


 }

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return arrayList.count
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return arrayList[section].myArray.count
}


override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as!TestTableCell

    let hh = indexPath.section

    cell.myTestView.text = (arrayList[hh].myArray as AnyObject) as? String

    cell.titleText.text = arrayList[hh].title


    return cell


 }


 }

and this is My Class : 这是我的课:

 class test : NSObject {


var myArray : NSArray = []

var title : String?

}

Your myArray is not array of string, it's dictionary. 您的myArray不是字符串数组,而是字典。 So if you want value of a,b and c in cell.myTestView.text. 因此,如果要在cell.myTestView.text中使用a,b和c的值。 Then you need to run loop to get all a,b and c in cell.myTestView.text. 然后,您需要运行循环以获取cell.myTestView.text中的所有a,b和c。

var string = ""

for (key, value) in arrayList[hh].myArray
{
    print("\(key) -> \(value)")
    string = string + "\n\(key) -> \(value)"
}

cell.myTestView.text = string

update your line cell.myTestView.text = (arrayList[hh].myArray as AnyObject) as? String 更新您的行cell.myTestView.text = (arrayList[hh].myArray as AnyObject) as? String cell.myTestView.text = (arrayList[hh].myArray as AnyObject) as? String with above code. 具有上述代码的cell.myTestView.text = (arrayList[hh].myArray as AnyObject) as? String

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用swift3将数据库存储到struct中? - How to store database into struct using swift3? 如何使用Swift3检测与Firebase数据库的互联网连接? - How to detect internet connection with Firebase Database using Swift3? Swift3 / Firebase数据库:如何获取值的子键? - Swift3/Firebase Database : How can I get sub key of value? 我可以使用swift3 iOS在一个UIViewcotroller中设置ModelClass并从另一个UIViewCotroller中读取ModelClass的对象吗? - Can I set a ModelClass in one UIViewcotroller and read the ModelClass' object from another UIViewCotroller using swift3 iOS? 如何在swift3中从Any获取字符串 - How can I get String from Any in swift3 如何使用 Swift 在 Firebase 中存储具有相同关键字的不同数据的多个实例? - How can I store multiple instances of different data with the same keyword in Firebase using Swift? 如何在Swift3中从UIView传递数据UIViewContoller - How can I passing data UIViewContoller from UIView in swift3 我如何在swift3的appleTvOS开发项目中将焦点从一个对象更改为我想要的下一个首选对象 - How can i change focus from one object to next preferred object which i want in appleTvOS development project in swift3 如何使用swift3从ios设备触发firebase的推送通知 - how to trigger push notifications of firebase from an ios device using swift3 如何使用 Swift 将 UIImage 上传到 REST API,作为 swift3 中的“source=”参数? - How can I upload a UIImage to an REST API using Swift, as a 'source=' parameter in swift3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM