내 큰 프로젝트의 일부인 내 VC 중 하나에 다음 코드가 있습니다. Firebase DB 참조 중 하나는 Sell_Request
입니다. 3 명의 자녀 (name
, latitude
및 longitude
)가 있지만 지금은 name
과 관련이 있습니다.TableView 셀에 Firebase의 데이터 표시
문자열 배열에 추가하려고하고 콘솔에도 인쇄하려고합니다. 콘솔에 인쇄되는 이름이 보이지만 개별 셀에 인쇄 된 이름이 표시되지 않습니다.
감사합니다. 데이터 소스 후 다시로드
import UIKit
import Firebase
import FirebaseDatabase
import MapKit
import CoreLocation
class RequestVC: UITableViewController, CLLocationManagerDelegate {
var locationManager = CLLocationManager()
var sellerUserNames = [String]()
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "backToMain" {
self.navigationController?.navigationBar.isHidden = true
}
}
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = manager.location?.coordinate {
let databaseRef = FIRDatabase.database().reference()
databaseRef.child("Sell_Request").queryOrderedByKey().observe(.childAdded, with: { (FIRDataSnapshot) in
if let data = FIRDataSnapshot.value as? NSDictionary {
if let name = data[Constants.NAME] as? String {
self.sellerUserNames.append(name)
print(name)
}
}
})
}
}
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 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return sellerUserNames.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = sellerUserNames[indexPath.row]
return cell
}
/*
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
수를 확인할 수 있습니까? 0A가 아닙니다. 메인 라인의 인쇄 라인 재로드 테이블 이후. –
안녕하세요, 당신은 tableview를 다시로드해야합니다. 귀하의 tableview 이름의 참조를 추가하십시오. tableView, if let 데이터 문의 끝에 self.tableView.reloadData()를 추가하십시오. – webjunkie
응답 해 주셔서 감사합니다. 변수 (var tableView : UITableView!)를 만들거나 IBOutlet (@IBOutlet var tableView : UITableView!) 또는 다른 것을 만드는 것을 의미합니까? – user2411290