Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何基于json值firebase实时数据库使单元格自动删除_Json_Swift_Xcode_Firebase_Firebase Realtime Database - Fatal编程技术网

如何基于json值firebase实时数据库使单元格自动删除

如何基于json值firebase实时数据库使单元格自动删除,json,swift,xcode,firebase,firebase-realtime-database,Json,Swift,Xcode,Firebase,Firebase Realtime Database,因此,我正在从firebase实时数据库检索数据,并将其全部提取出来,我需要每个单元格仅在其子“升级”的值为“是”时显示父俱乐部,如果不是,我需要该单元格删除自身,并且只有3个俱乐部升级过,且等于“是” 它把它全部拉出来,并在屏幕上显示出来,但我一直在想如何删除那些孩子们没有提升为“是”的单元格 //NightClubs.swift 进口基金会 导入UIKit 班级夜总会{ 私有变量名称:字符串! 私有变量位置:字符串! 私有变量地址:字符串! 私有变量:字符串! 私有变量经度:字符串! 私有变

因此,我正在从firebase实时数据库检索数据,并将其全部提取出来,我需要每个单元格仅在其子“升级”的值为“是”时显示父俱乐部,如果不是,我需要该单元格删除自身,并且只有3个俱乐部升级过,且等于“是”

它把它全部拉出来,并在屏幕上显示出来,但我一直在想如何删除那些孩子们没有提升为“是”的单元格

//NightClubs.swift
进口基金会
导入UIKit
班级夜总会{
私有变量名称:字符串!
私有变量位置:字符串!
私有变量地址:字符串!
私有变量:字符串!
私有变量经度:字符串!
私有变量:字符串!
私有变量类型:字符串!
private var_liveCount:String!
私人变量:字符串!
私有变量描述:字符串!
变量名称:字符串{
返回\u名称
}
变量位置:字符串{
返回位置
}
变量地址:字符串{
返回地址
}
变量纬度:字符串{
返回纬度
}
变量经度:字符串{
返回经度
}
var:字符串{
回归!
}
变量类型:字符串{
返回类型
}
var-liveCount:String{
返回_liveCount
}
var goingCount:字符串{
返回计数
}
变量描述:字符串{
返回描述
}
init(名称:String,位置:String,地址:String,纬度:String,经度:String,升级:String,类型:String,liveCount:String,goingCount:String,描述:String){
self.\u name=name
自身位置=位置
self.\u address=地址
自身纬度=纬度
自身经度=经度
自我提升=提升
自身类型=类型
self.\u liveCount=liveCount
自我。_goingCount=goingCount
自我描述=描述
}
初始化(barData:字典){
如果让name=barData[“name”]作为字符串{
self.\u name=name
}
如果let location=barData[“location”]作为字符串{
自身位置=位置
}
如果let address=barData[“address”]作为字符串{
self.\u address=地址
}
如果让纬度=barData[“纬度”]作为?字符串{
自身纬度=纬度
}
如果让经度=barData[“经度”]作为?字符串{
自身经度=经度
}
如果让promoted=barData[“promoted”]作为?字符串{
自我提升=提升
}
如果let type=barData[“type”]as?字符串{
自身类型=类型
}
如果让liveCount=barData[“liveCount”]作为?字符串{
self.\u liveCount=liveCount
}
如果让goingCount=barData[“goingCount”]作为?字符串{
自我。_goingCount=goingCount
}
如果let description=barData[“description”]作为字符串{
自我描述=描述
}
}
}

我希望它基本上只显示3个子项,其中子项等于“是”,并且没有错误,因为我根本没有做任何事情来更改它

您可以执行以下操作之一:

1) 在finalBar数组中添加提升值为“Yes”的唯一条。对于此更新,您的数据获取代码应该如下所示

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)
               // Add this check here
               if bar.promoted == "Yes" {
                   self.finalBar.append(bar)
               }
               print(self.finalBar)
            }
        }
    }
    self.tempTableView.reloadData()
 })
//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
        }
    }
}
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)
               // Add this check here
               if bar.promoted == "Yes" {
                   self.finalBar.append(bar)
               }
               print(self.finalBar)
            }
        }
    }
    self.tempTableView.reloadData()
 })
 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)
                }
            }
            //Add this to filter the bars with promoted as "yes".
            //Then use this array in tableView delegate and datasource methods
            filteredFinalBars = finalBar.filter { $0.promoted == "Yes"}
        }
        self.tempTableView.reloadData()
     })