I have a TableView with a bar button item. When I click bar button it's show the PopOver menu. when I click the Popover menu items perform some actions (like tableview data with specific items) I want use PopOver menu as a Filter type:
This is the code :
View Controller code
@IBAction func ButtonClick(_ sender: UIBarButtonItem) {
self.performSegue(withIdentifier: "POP1", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "POP1"
{
let dest = segue.destination
if let pop = dest.popoverPresentationController
{
pop.delegate = self
}
}
}
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return fruits.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let fruitName = fruits[indexPath.row]
cell.textLabel?.text = fruitName
return cell
}
PopOVER Code:
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "POP", for: indexPath)
cell.textLabel?.text = data[indexPath.row]
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
var selectedItem = indexPath
print (selectedItem.row)
}
when I click one in Popover menu it should show the count of words starting with each letter (1 from A, 2 from B) displayed on view controller table view.