I created a Custom Cell to replace UITableViewSectionHeader
with a protocol to process when UISegmentedControl.index
is changed so i can order the table by name or value:
import UIKit
protocol OrdenarTableViewDelegate {
func ordenarTableView(cell: OrdenarTableViewCell)
}
class OrdenarTableViewCell: UITableViewCell {
var delegate: OrdenarTableViewDelegate?
@IBOutlet weak var segmentedOrdenar: UISegmentedControl!
@IBAction func alteraOrdenacao(sender: UISegmentedControl) {
delegate?.ordenarTableView(self)
}
On the UITableViewControler I referenced the protocol
class SelecionadasTableViewController: UITableViewController, UITextFieldDelegate, OrdenarTableViewDelegate {
and implemented it:
// MARK: - Ordenar Delegate
func ordenarTableView(cell: OrdenarTableViewCell) {
if cell.segmentedOrdenar.selectedSegmentIndex == 0 {
listaCervejas = bancoDeDados.selecionaCervejas(false)
} else {
listaCervejas = bancoDeDados.selecionaCervejas(true)
}
ordenarCervejas = cell.segmentedOrdenar.selectedSegmentIndex
tableView.reloadData()
}
When I select the index 1, the app works just fine, but when index 0 is selected the action is only performed if click on a UITextField
on any other cell or I pull the table down for refreshing (which by the way is not implemented to refresh)
Is there anything that I'm missing? Because it just feels really awkward.