Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I change placeholder's title and subtitle when I am calling showNoConnectionPlaceholder() and others? #18

Closed
junweimah opened this issue Jan 2, 2018 · 12 comments
Labels

Comments

@junweimah
Copy link

I have a simple question, sorry for being a ios newbie.

How do I change the title and sub title wording as I am displaying the placeholders?

I found out that the wordings are in PlaceholderData.swift, in public struct PlaceholderData.

Lets say I do not wish to hard code them here, but set it to something when I am calling tableView.showNoConnectionPlaceholder(), how do I do it?

I also found the file PlaceholdersProvider.swift, which I set it to be :

var noConnectionData: PlaceholderData = .noConnection
        noConnectionData.image = #imageLiteral(resourceName: "hg_default-error")
        noConnectionData.title = "Testing no connection title"
        noConnectionData.subtitle = "Testing no connection sub title"
        let noConnection = Placeholder(data: noConnectionData, style: commonStyle, key: .noConnectionKey)

But the message is still the same

How do I do it?

Thanks

@HamzaGhazouani
Copy link
Owner

HamzaGhazouani commented Jan 2, 2018

Hi @junweimah,
Thank you for your question.
You could find below an example to change the title of the default theme:

let provider: PlaceholdersProvider = .default
 
var noResultsData: PlaceholderData = .noResults
noResultsData.title = "My custom title"
let noResultsPlaceholder = Placeholder(data: noResultsData, style: PlaceholderStyle(), key: .noResultsKey)
provider.add(placeholders: noResultsPlaceholder)
        
placeholderTableView?.placeholdersProvider = provider

This is what you are looking for ?
Hamza

@junweimah
Copy link
Author

@HamzaGhazouani
I will test it out and get back to you

@junweimah
Copy link
Author

Where should I place this code in?

@HamzaGhazouani
Copy link
Owner

You can put it in the viewDidLoad for example

@junweimah
Copy link
Author

I tried in viewDidLoad, but nothing is showing

@HamzaGhazouani
Copy link
Owner

can you please share the code of your controller ?

@junweimah
Copy link
Author

junweimah commented Jan 3, 2018

in viewDidLoad

if Connectivity.isConnectedToInternet { //tested, working with wifi, not yet tested with mobile data
            print("*** phone is Connected to the internet ")            
        }
        else{
            print("*** phone is Not connected to the Internet")
            //test a custom placeholder
            let provider: PlaceholdersProvider = .default
            
            var noResultsData: PlaceholderData = .noResults
            noResultsData.title = "My custom title"
            let noResultsPlaceholder = Placeholder(data: noResultsData, style: PlaceholderStyle(), key: .noResultsKey)
            provider.add(placeholders: noResultsPlaceholder)
            
            self.tvBug.placeholdersProvider = provider
//            tvBug.showNoConnectionPlaceholder()
        }

Edit:

if I am using tvBug.showNoConnectionPlaceholder(), then it works, but using the default wording

@HamzaGhazouani
Copy link
Owner

Try this:

 //test a custom placeholder
let provider: PlaceholdersProvider = .default
var noConnectionData: PlaceholderData = .noConnection
noConnectionData.title = "My custom title"
let noConnectionPlaceholder = Placeholder(data: noConnectionData, style: PlaceholderStyle(), key: .noConnectionKey)
provider.add(placeholders: noConnectionPlaceholder)
self.tvBug.placeholdersProvider = provider

if Connectivity.isConnectedToInternet == false { //tested, working with wifi, not yet tested with mobile data
    tvBug.showNoConnectionPlaceholder()
}

@junweimah
Copy link
Author

Wow, it works!

Thanks !

So I have to have the whole block of code to cuztomize it :

let provider: PlaceholdersProvider = .default
var noConnectionData: PlaceholderData = .noConnection
noConnectionData.title = "My custom title"
let noConnectionPlaceholder = Placeholder(data: noConnectionData, style: PlaceholderStyle(), key: .noConnectionKey)
provider.add(placeholders: noConnectionPlaceholder)
self.tvBug.placeholdersProvider = provider

and then finally use it when I want to display using :

tvBug.showNoConnectionPlaceholder()

correct?

I will find a way to further simplify the code.

Thanks!

@HamzaGhazouani
Copy link
Owner

Yes exactly, any PR is welcome ;)

@umair2ooo
Copy link

umair2ooo commented Aug 10, 2018

In this way,
This will add place holder every time when you call it.
This is not a solution.
It suppose to be have a flexibility to pass, "Title", "Subtitle", "Action" bla bla bla, In custom placeHolder like,

self.tableView_.showLoadingPlaceholder(title: "This is optional Title", subtitle: "This is optional Subtitle", action: "This is optional action")

@umair2ooo
Copy link

It will be good if you put it at high priority,
We need it ASAP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants