HamzaGhazouani/HGPlaceholders

Your placeholdersProvider is not configured correctly, no placeholder with key: emptyPlaceHolder found!

tarshadesouza opened this issue · 3 comments

Im not sure how to configure a custom cell.. I get the error above. and for the life of me cant figure out as to why!

  extension PlaceholdersProvider {
    static var emptyProfileVC: PlaceholdersProvider {
        var commonStyle = PlaceholderStyle()
        commonStyle.backgroundColor = UIColor(red: 1.0, green: 236.0/255, blue: 209.0/255.0, alpha: 
          1.0)
        commonStyle.actionBackgroundColor = .black
        commonStyle.actionTitleColor = .white
        commonStyle.titleColor = .black
        commonStyle.isAnimated = false
    
        commonStyle.titleFont = UIFont(name: "AvenirNextCondensed-HeavyItalic", size: 19)!
        commonStyle.subtitleFont = UIFont(name: "AvenirNextCondensed-Italic", size: 19)!
        commonStyle.actionTitleFont = UIFont(name: "AvenirNextCondensed-Heavy", size: 19)!
    
        var loadingStyle = commonStyle
        loadingStyle.actionBackgroundColor = .clear
        loadingStyle.actionTitleColor = .gray
    
        var loadingData: PlaceholderData = .loading
        loadingData.image = #imageLiteral(resourceName: "Compass")
        let loading = Placeholder(data: loadingData, style: loadingStyle, key: .loadingKey)
    
    var errorData: PlaceholderData = .error
    errorData.image = #imageLiteral(resourceName: "comment")
    let error = Placeholder(data: errorData, style: commonStyle, key: .errorKey)
    
    var noResultsData: PlaceholderData = .noResults
    noResultsData.image = #imageLiteral(resourceName: "clock")
    let noResults = Placeholder(data: noResultsData, style: commonStyle, key: .noResultsKey)
    
    var noConnectionData: PlaceholderData = .noConnection
    noConnectionData.image = #imageLiteral(resourceName: "clock")
    let noConnection = Placeholder(data: noConnectionData, style: commonStyle, key: .noConnectionKey)
    
    let placeholdersProvider = PlaceholdersProvider(loading: loading, error: error, noResults: noResults, noConnection: noConnection)
    
    let xibPlaceholder = Placeholder(cellIdentifier: "placeHolder", key: PlaceholderKey.custom(key: "XIB"))
    
    placeholdersProvider.add(placeholders: PlaceholdersProvider.createProfileVCPlaceHolder(), xibPlaceholder)
    
    return placeholdersProvider
}


static func createProfileVCPlaceHolder ()-> Placeholder {
    var placeHolderData: PlaceholderData = .noResults
    
    var placeHolderStyle = PlaceholderStyle()
    placeHolderStyle.backgroundColor = .black
    placeHolderStyle.actionBackgroundColor = .clear
    placeHolderStyle.actionTitleColor = .white
    placeHolderStyle.titleColor = .white
    placeHolderStyle.isAnimated = false
    
    placeHolderData.title = NSLocalizedString("\"This is a new day, a\nnew beginning\"", comment: "")
    placeHolderData.subtitle = NSLocalizedString("Star Wars", comment: "")
    placeHolderData.image = #imageLiteral(resourceName: "Heartfilled")
    placeHolderData.action = NSLocalizedString("OK!", comment: "")
    
    let placeholder = Placeholder(data: placeHolderData, style: placeHolderStyle, key: PlaceholderKey.custom(key: PlaceHolderGenerator.PlaceHolderKeys.ProfileVC.rawValue))
    
    return placeholder
}

}

my code is exactly the same as the demo just with different keys..

OK so after two days i got desperate and posted this^^ after 40mins of posting this I figured out the issue. Im merely answering as to if anyone has an issue like me they dont waste their time hahah.

In my tableview class I was setting the provider like this
let prov = placeholderProvider.default (or your theme if you make one)

instead of this ^ use the instance that you have of the object :tableView
in my case I have my tableView instance and a, var placeHolderView : TableView?

when setting the placeholder provider use the instance with the type TableView..
eg.
placeHolderView.placeholderProvider and so on...
not (if you already have) the instance of the tableview from storyboard..
I hope this helps I understand it may not be clear.. But just trying to help ;)

Cool, thanks @tarshadesouza for your contribution, don't hesitate to add some clarification in the README, and create a PR :)
thanks again