Home>
Development environment
Xcode11.0
Swift5.1
firebase3
I have implemented a matching app function.
You are registered with Firebase.
I want to call data from Firebase and display the data one by one in the Label placed in the TableViewCell
-Call the data registered in Firebase and store it in the array
・ Store the stored data one by one in the Label in the TableViewCell and display it
You can call data from Firebase
However, it cannot be displayed in the Label inside the TableViewCell
I tried to display in TableView (without Label), but it was not displayed.
import UIKit
import Firebase
import SwiftyJSON
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var TableView: UITableView!
let ref: DatabaseReference = Database.database (). reference ()
// prepare an empty array
var Array_Title: [String] = []
override func viewDidLoad () {
super.viewDidLoad ()
ref.child ("Sample"). observe (.value, with: {(snapshot: DataSnapshot) in
// Get Firebase data in JSON format
let getjson = JSON (snapshot.value as? [String: AnyObject] ?? [:])
// Do nothing if the data is 0
if getjson.count == 0 {
return
}
for (key, _) in getjson.dictionaryValue {
// Store the called data in an array
self.Array_Title.append ("\ (getjson [key] [" Title "]. stringValue)")
}
// Display array on console
print (self.Array_Title)
self.TableView.reloadData ()
})
}
// count array and return number of cells
func tableView (_ tableView: UITableView, numberOfRowsInSection section: Int)->Int {
return Array_Title.count
}
func tableView (_ tableView: UITableView, cellForRowAt indexPath: IndexPath)->UITableViewCell {
let cell = tableView.dequeueReusableCell (withIdentifier: "TableViewCell", for: indexPath) as! TableViewCell
// Enter a value for the cell label.
cell.Title.text = Array_Title [indexPath.row]
return cell
}
}
import UIKit
class TableViewCell: UITableViewCell {
@IBOutlet weak var Title: UILabel!
override func awakeFromNib () {
super.awakeFromNib ()
// Initialization code
}
override func setSelected (_ selected: Bool, animated: Bool) {
super.setSelected (selected, animated: animated)
// Configure the view for the selected state
}
}
-
Answer # 1
-
Answer # 2
cell.ViewCellLabel.text = Array_Title [indexPath.row]
Is this strange? ? ? Is it an error?
If you look at Custom cell,
@IBOutlet weak var Title: UILabel!
so
cell.Title.text = ...
Isn't it necessary to write? ? ?
Related articles
- swift - when you tap a tableview cell displaying firestore data, you want to get the document id of that cell
- java - "gas" i want to reflect the information of the error mail that returns to gmail in the spreadsheet
- swift - where to record information such as profiles
- i want to reflect the information registered on the edit screen with php
- Swift TableView implements freeze pane functionality
- Swift achieves multiple TableView sideslip and switch effects
- docker - how to get information on prometheus and reflect the exporter
- ios - [swift 5] i want to reflect the color changed by textview on the label of a different screen
- [swift] how to implement context menu in tableview of macos
- ruby - i want to reflect the db information on heroku
- swift: when you tap the cell of the transition destination tableview, you want to display the character in that cell
- [swift5] i want to reflect the schedule of the date tapped on the calendar app in tableview
- html - i want to reflect the seed information, but i cannot respond because an error occurs
- swift - animation behavior of tableview accordion customheader is strange
- swift - i want to put a tableview in the segmented control
- swift - tableview gets nil error when using segementslide
- ios, swift i want to reload the tableview using containerview
- ruby - [rails] i want to reflect the information selected in the previous action in the transition destination action
- [swift] i want to display the information of the selected cell at the transition destination
- ios - [swift] i want to move tableview cells by dragging and dropping
Related questions
- Swift | How to determine the index of the cell where the button was clicked?
- website - questions about technology selection for personal development
- swift - unable to display tableview
- xcode - [swift] i want to display another hidden cell when i tap tableviewcell
- analytics collection is not disabled on ios [firebase]
- swift - about firebase/rules
- swift - i want to resolve a build-time error in firebase/analytics
- xcode - i want to display images using firebase storage with swift
- swift - when scrolling tableview, uilabel of sectionheaderview fades in from the side
- ios - i'm stuck with a basic tableview display
https://www.youtube.com/watch?v=zgVW3s9W88k
I did it after referring to the link above!
Thank you very much.