HamzaGhazouani / HGPlaceholders

Nice library to show placeholders and Empty States for any UITableView/UICollectionView in your project
MIT License
2.2k stars 159 forks source link

Error EXC_BAD_ACCESS (code=2, address=...) #44

Open matejhocevar opened 6 years ago

matejhocevar commented 6 years ago

Hey!

I'm new to iOS development. And I found this plugin very interesting, so I want to implement it. But I stumble upon a problem that I cannot resolve.

My code like looks like this:

...
import HGPlaceholders

class MyViewController: BaseViewController {

    @IBOutlet var myTableView: TableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        ...

        configureTableView()

        ...
    }
}

extension MyViewController: UITableViewDelegate, UITableViewDataSource {
    func configureTableView() {
        myTableView.delegate = self
        myTableView.dataSource = self
        myTableView.placeholderDelegate = self     // <- ERROR: EXC_BAD_ACCESS (code=2, address=0x1b4b2ec80)

        ..

        myTableView.register(UINib(nibName: "MyCell", bundle: nil), forCellReuseIdentifier: "MyItemCell")

        ...
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        ...
    }

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

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        myTableView.deselectRow(at: indexPath, animated: true)
        myTableView.showLoadingPlaceholder()
    }
}

I got an error EXC_BAD_ACCESS (code=2, address=0x1b4b2ec80) at the line myTableView.placeholderDelegate = self.

Can someone help me?

Thank you

Idomo commented 6 years ago

Where did you implement PlaceholderDelegate? You can’t say that the placeholderDelegate = self if self doesn’t implement the delegate at any extension.

Binusz commented 6 years ago

You need to call placeholderDelegate optional. like that; myTableView?.placeholderDelegate = self