1

Tengo la siguiente tabla

@IBOutlet weak var menuTableView: UITableView!

La cual completo con el siguiente codigo

override func viewWillAppear(_ animated: Bool) {
    menuTableView.reloadData()
}

// MARK: - Table view data source
func numberOfSections(in tableView: UITableView) -> Int {
    return 6
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 15
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let mainCell = Bundle.main.loadNibNamed("PanelHomeTableViewCell", owner: self, options: nil)?.first as! PanelHomeTableViewCell
    mainCell.selectionStyle = .none
    mainCell.backgroundColor = Utils.Color.COLOR_E8E8E8

    mainCell.strLblTitleOptionsMenu.textColor = Utils.Color.COLOR_2B5034
    switch (indexPath.section)
    {
    case 0:
        mainCell.strLblTitleOptionsMenu.text = NSLocalizedString("strLblOption1",comment:"")
        mainCell.imgOptionsMenu.image = UIImage.init(named:"PagarMenu")
        return mainCell
    case 1:
        mainCell.strLblTitleOptionsMenu.text = NSLocalizedString("strLblOption2",comment:"")
        mainCell.imgOptionsMenu.image = UIImage.init(named:"BillingMenu")
        return mainCell
    case 2:
        mainCell.strLblTitleOptionsMenu.text = NSLocalizedString("strLblOption3",comment:"")
        mainCell.imgOptionsMenu.image = UIImage.init(named:"CollectionNotificationsMenu")
        return mainCell
    case 3:
        mainCell.strLblTitleOptionsMenu.text = NSLocalizedString("strLblOption4",comment:"")
        mainCell.imgOptionsMenu.image = UIImage.init(named:"billingQueryMenu")
        return mainCell
    case 4:
        mainCell.strLblTitleOptionsMenu.text = NSLocalizedString("strLblOption5",comment:"")
        mainCell.imgOptionsMenu.image = UIImage.init(named:"MovsBalanceMenu")
        return mainCell
    case 5:
        mainCell.strLblTitleOptionsMenu.text = NSLocalizedString("strLblOption6",comment:"")
        mainCell.imgOptionsMenu.image = UIImage.init(named:"CashOutMenu")
        return mainCell
    default:
        break
    }
    return mainCell
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 40
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    switch (indexPath.section)
    {
    case 0:
        self.presenter.postPayment()
        break
    case 1:
        self.presenter.collectPayment()
        break
    case 2 :
        self.presenter.queryNotifications()
        break
    case 3:
        self.presenter.queryCollection()
        break
    case 4:
        self.presenter.getMovements()
        break
    case 5:
        self.presenter.atmWithdrawal()
        break
    default:
        break
    }
    tableView.deselectRow(at: indexPath, animated: true)
}   

El cual me deja un header vacío de alto 15, pero el fondo de mi pantalla es blanco, y este header es como gris. Quisiera poder ponerlo en blanco, puede ser a código Swift o directamente desde las herramientas visuales.

Gracias.

1 respuesta 1

3

Usando el método tableView(_:viewForHeaderInSection:) de tu UITableViewDelegate puedes configurar el header como quieras.

Ver la documentación (en inglés).

Sería algo así:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let viewFrame = CGRect(x: 0, y: 0, width: tableView.bounds.width, height: 15)
    var headerView = UIView(frame: viewFrame)
    headerView.backgroundColor = UIColor.white
    return headerView
}
1
  • Me di cuenta antes de que editaras que solo con poner UIView() ya funciona , aunque ese viewFrame para ponerle altura esta bueno , aunque en mi caso ya lo tenia en el otro metodo que pide la altura , gracias el 18 abr. 2018 a las 13:46

Tu Respuesta

Al pulsar en “Publica tu respuesta”, muestras tu consentimiento a nuestros términos de servicio, política de privacidad y política de cookies

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.