I have a PFQueryTableViewController
which lists films. In my navigation bar, I have a filter button, which when the user presses it, it displays a UIPopoverPresentationController
. This popover simply displays some options in a UITableView. See the image below:
Goal
When the user selects an option in the popover, I need the option index to be passed back to the main PFQueryTableViewController
and then update the table accordingly. And to also close the popover controller.
I already know how I can sort the table, I just need to know how to pass the selected option back, and then how to add it into the if
statement to filter my Parse query. For example if the user selected to filter by Highest rated, in my queryForTable()
function, I'll put something like:
if XXXXXXXXXXXX {
query.orderByDescending("highestRated")
}
And I've already created the popover VC and it works.
Hopefully this makes sense...if not please ask more info. The code for my popover VC is below:
class SortByViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var sortByTableView: UITableView!
var sortByOptions = ["Date added", "Film name", "Our star rating", "Highest rated", "Lowest rated", "Director's name"]
override func viewDidLoad() {
super.viewDidLoad()
self.sortByTableView.rowHeight = 44.0
sortByTableView.tableFooterView = UIView(frame:CGRectZero)
sortByTableView.backgroundColor = UIColor.clearColor()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sortByOptions.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = sortByTableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.text = self.sortByOptions[indexPath.row]
let imageName = UIImage(named: sortByOptions[indexPath.row])
cell.imageView?.image = imageName
let itemSize:CGSize = CGSizeMake(30, 30)
UIGraphicsBeginImageContextWithOptions(itemSize, false, UIScreen.mainScreen().scale)
let imageRect : CGRect = CGRectMake(0, 0, itemSize.width, itemSize.height)
cell.imageView!.image?.drawInRect(imageRect)
cell.imageView!.image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
cell.textLabel?.textColor = UIColor(hue: 359/360, saturation: 67/100, brightness: 71/100, alpha: 1)
cell.backgroundColor = UIColor.clearColor()
return cell
}
}