I have object named myArray in firebase database structure and it has a multiple lines of strings as [a , b and c ] like this how can I display this object in my Table View ,When I run it its coming in My Debug like this but its not appears in my simulator its appease like this ,I am using 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. So if you want value of a,b and c in cell.myTestView.text. Then you need to run loop to get all a,b and c in cell.myTestView.text.
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
with above code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.