Dealing with Complex Table Views in iOS and Keeping Your Sanity
Marin Benčević
3.9K25

Great article on UITableView, Here I use below code to deal with empty tableview

public func numberOfSections(in tableView: UITableView) -> Int {
var numberOfSection = 0
if self.dataObject.count > 0 {
    self.tableView.separatorStyle = .singleLine
    numberOfSection = 1
    self.tableView.backgroundView = nil
} else {
    let noDataLabel = UILabel()
    noDataLabel.frame = CGRect(x: 0, y: 0, width:          self.tableView.frame.size.width, height: 40)
    noDataLabel.text = "No Data Available"
    noDataLabel.textColor = UIColor.darkGray
    noDataLabel.textAlignment = .center
    noDataLabel.font = UIFont(name: "HelveticaNeue", size: 16)
    self.tableView.separatorStyle = .none
    self.tableView.backgroundView = noDataLabel
}
return numberOfSection
}