Hi I have searched stack overflow and saw If no Table View results, display "No Results" on screen which is useful but not exactly what i am looking for. My problem is when i follow these steps it works correctly. but if my tableview does end up having data it will flash my "empty tableview label" for a second or 2 before populating my data. It looks terrible in my opinion.
I have a label connected through outlet on my tableview called emptyTableViewlbl. This is my code being called in. Thanks in advance any help is appreciated. Thank you
extension FeedViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if posts.isEmpty {
emptyTableViewLbl.isHidden = false
emptyTableViewLbl.text = "Empty tableview label"
return 0
} else {
emptyTableViewLbl.isHidden = true
}
return posts.count
}
and have tried
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
loadPosts()
if posts.isEmpty {
emptyTableViewLbl.isHidden = false
emptyTableViewLbl.text = "Empty"
} else {
emptyTableViewLbl.isHidden = true
}
}