Итак, я извлекаю данные из базы данных Firebase в реальном времени и извлекаю их все, и мне нужно, чтобы каждая ячейка показывала родительский клуб только в том случае, если его дочерний элемент «Повышен» имеет значение «Да», а если нет, мне нужен ячейка для удаления сама, и только 3 клуба когда-либо продвигались, чтобы быть равными «Да»
он вытягивает все это и отображает все это на экране, но я застрял на том, как удалить ячейки, в которых дети не выдвинули значение «Да»
//tempViewController.swift
import Foundation
import UIKit
import FirebaseDatabase
class tempViewController: UIViewController , UITableViewDelegate , UITableViewDataSource {
@IBOutlet weak var tempTableView: UITableView!
var finalBar = [NightClubs]()
override func viewDidLoad() {
super.viewDidLoad()
tempTableView.dataSource = self
tempTableView.delegate = self
DataService.ds.REF_BARS.observeSingleEvent(of: .value, with: { (snapshot) in
print(snapshot.value as Any)
if let snapshot = snapshot.children.allObjects as? [DataSnapshot] {
for snap in snapshot {
print(snap)
if let barData = snap.value as? Dictionary<String, AnyObject> {
let bar = NightClubs(barData: barData)
self.finalBar.append(bar)
print(self.finalBar)
self.tempTableView.reloadData()
}
self.tempTableView.reloadData()
}
self.tempTableView.reloadData()
}
self.tempTableView.reloadData()
})
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView( _ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return finalBar.count
}
func tableView( _ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tempTableView.dequeueReusableCell(withIdentifier: "newCell") as! newCell
let barz = finalBar[indexPath.row]
if barz.promoted == "Yes" {
cell.setData(data: barz)
// this sends the nightclubs that have .promoted == "Yes"
} else {
// need to remove the cell from the user view
// as only 3 NightClubs will have promoted == "Yes"
// so i only want to see 3 cells
}
return cell
}
}
//newCell.swift
import Foundation
import UIKit
class newCell: UITableViewCell {
@IBOutlet weak var nameTextLabel: UILabel!
@IBOutlet weak var locationTextLabel: UILabel!
func setData(data: NightClubs) {
nameTextLabel.text = data.name
locationTextLabel.text = data.location
}
}
//NightClubs.swift
import Foundation
import UIKit
class NightClubs {
private var _name: String!
private var _location: String!
private var _address: String!
private var _latitude: String!
private var _longitude: String!
private var _promoted: String!
private var _type: String!
private var _liveCount: String!
private var _goingCount: String!
private var _description: String!
var name: String! {
return _name
}
var location: String! {
return _location
}
var address: String! {
return _address
}
var latitude: String! {
return _latitude
}
var longitude: String! {
return _longitude
}
var promoted: String! {
return _promoted
}
var type: String! {
return _type
}
var liveCount: String! {
return _liveCount
}
var goingCount: String! {
return _goingCount
}
var description: String! {
return _description
}
init(name: String, location: String, address: String, latitude: String, longitude: String, promoted: String, type: String, liveCount: String, goingCount: String, description: String) {
self._name = name
self._location = location
self._address = address
self._latitude = latitude
self._longitude = longitude
self._promoted = promoted
self._type = type
self._liveCount = liveCount
self._goingCount = goingCount
self._description = description
}
init(barData: Dictionary<String, AnyObject>) {
if let name = barData["Name"] as? String {
self._name = name
}
if let location = barData["Location"] as? String {
self._location = location
}
if let address = barData["Address"] as? String {
self._address = address
}
if let latitude = barData["Latitude"] as? String {
self._latitude = latitude
}
if let longitude = barData["Longitude"] as? String {
self._longitude = longitude
}
if let promoted = barData["Promoted"] as? String {
self._promoted = promoted
}
if let type = barData["Type"] as? String {
self._type = type
}
if let liveCount = barData["LiveCount"] as? String {
self._liveCount = liveCount
}
if let goingCount = barData["GoingCount"] as? String {
self._goingCount = goingCount
}
if let description = barData["Description"] as? String {
self._description = description
}
}
}
Я ожидал, что он в основном просто покажет 3 детей, где их дети равны "Да", и нет ошибки, потому что я ничего не делаю, чтобы изменить его