Placeholders not showing
andrecrimb opened this issue · 7 comments
Hey I'm writing the follow code on my tableView
`
import UIKit
import HGPlaceholders
class SentMemesTVC: UITableViewController{
var placeholderTableView: TableView?
var memes = [Meme]()
override func viewDidLoad() {
super.viewDidLoad()
self.clearsSelectionOnViewWillAppear = false
reloadTable()
NotificationCenter.default.addObserver(self, selector: #selector(reloadTable), name: NSNotification.Name(rawValue: NOTIF_RELOAD_TABLE), object: nil)
placeholderTableView = tableView as? TableView
placeholderTableView?.placeholderDelegate = self as PlaceholderDelegate
placeholderTableView?.placeholdersProvider = .basic
placeholderTableView?.showErrorPlaceholder()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == TO_MEME_EDITOR{
if let memeEditor = segue.destination as? MemeMainVC{
if let meme = sender as? Meme{
memeEditor.meme = meme
}
}
}
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return memes.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier: "MemeTableCell", for: indexPath) as? MemeTableCell{
let memeCell = memes[indexPath.row]
cell.configureCell(meme: memeCell)
return cell
}
return UITableViewCell()
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let meme: Meme = memes[indexPath.row]
performSegue(withIdentifier: TO_MEME_EDITOR, sender: meme)
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 114
}
@objc func reloadTable(){
let appDelegate = UIApplication.shared.delegate as! AppDelegate
memes = appDelegate.memes
self.tableView.reloadData()
}
@IBAction func toMemeEditor(_ sender: Any){
performSegue(withIdentifier: TO_MEME_EDITOR, sender: nil)
}
}
extension SentMemesTVC: PlaceholderDelegate {
func view(_ view: Any, actionButtonTappedFor placeholder: Placeholder) {
print(placeholder.key.value)
placeholderTableView?.showDefault()
}
}
`
but nothing is happening
Hi @andrerosa189, you instantiate the table view via storyboard or by code ?
Sorry, but how do I do that?
Thanks, I got it
Ok :)
So does this work with Storyboard? I followed the example demo, but the placeholder doesn't show up.
import UIKit
import HGPlaceholders
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
lazy var tableView:UITableView = {
let tableview = UITableView()
tableview.tableFooterView = UIView()
tableview.allowsSelection = false
tableview.translatesAutoresizingMaskIntoConstraints = false
tableview.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
tableview.delegate = self as UITableViewDelegate
tableview.dataSource = self as UITableViewDataSource
return tableview
}()
var placeHolderView:TableView?
my viewDidLoad
placeHolderView?.delegate = self
placeHolderView?.dataSource = self
placeHolderView?.placeholdersProvider = .basic
placeHolderView?.placeholderDelegate = self as? PlaceholderDelegate
After my network call I do the following.
if self.results.count == 0{
self.placeHolderView?.showNoResultsPlaceholder()
}else{
self.placeHolderView?.reloadData()
}
And nothing happens. I've verified, that my results.count is 0, and still no No Results Placeholder is displayed
.
Edit: I've added the necessary constraints for my tableview and it is shows up when I use tableView.reloadData().
Where have I gone wrong?