Is there any way to delete a row from a PFQuery if a condition is met?

146 views Asked by At

I'm trying to remove a row if the condition retrieved from var cellStatus = object["active"] as! Bool is false. I've tried a couple of different things and cant seems to get anything to work. Hiding the cell just leaves a large gap in the tableView.

class TableViewController: PFQueryTableViewController {

    override init(style: UITableViewStyle, className: String!) {
        super.init(style: style, className: className)
    }

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        self.parseClassName = "specials"
        self.pullToRefreshEnabled = true
    }

    // Define the query that will provide the data for the table view
    override func queryForTable() -> PFQuery {
        var query = PFQuery(className: parseClassName!)
        query.limit = 6
        query.orderByAscending("specialRank")
        return query
    }

    //override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject!) -> PFTableViewCell {

        var cellStatus = object["active"] as! Bool

        var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! PFTableViewCell!

        if cell == nil {
            cell = PFTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
        }

        if let locationName = object["locName"] as? String {
            cell?.textLabel?.text = locationName
        }
        if let spec = object["special"] as? String {
            cell?.detailTextLabel?.text = spec
        }

        return cell
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        // Get the new view controller using [segue destinationViewController].
        var detailScene = segue.destinationViewController as! DrinkInfoViewController

        // Pass the selected object to the destination view controller.
        if let indexPath = self.tableView.indexPathForSelectedRow() {
            let row = Int(indexPath.row)
            detailScene.currentObject = objects?[row] as? PFObject!
        }
    }

    override func viewWillAppear(animated: Bool)    
    {
        self.navigationController?.navigationBarHidden = false
    }
}
0

There are 0 answers