En mi opinión, Controlador, estoy usando UITableView, en que cada celda personalizada estoy cargando datos de diferentes matrices, ahora si una celda en particular no tiene datos, se muestran NO-Data
pero ahora si cada celda no tiene datos, entonces quiero ocultar UITableView y mostrar No-Data
imagen. Alguien me puede ayudar.
En este momento pensé en contar varias matrices y comprobar si está vacío o no. Pero creo que no sería una solución viable.
¿Alguien tiene mejor solución para esto?
Respuestas
0 para la respuesta № 1Prueba esto:-
if self.ary.count == 0 && self.ary1.count == 0 //multiple arrays
{
self.tableview.setBackgroundText(stringValue: "No Data")
}
extension UITableView {
func setBackgroundText(stringValue:String) {
let backgroundLabel = UILabel()
backgroundLabel.textColor = UIColor.blue
backgroundLabel.numberOfLines = 0
backgroundLabel.textAlignment = .center
backgroundLabel.text = stringValue
backgroundLabel.autoresizingMask = [.flexibleWidth, .flexibleHeight]
backgroundLabel.translatesAutoresizingMaskIntoConstraints = true
self.backgroundView = backgroundLabel
self.backgroundView?.backgroundColor = .red
}
func removeBackgroundText() {
self.backgroundView = nil
}
}