HamzaGhazouani / HGPlaceholders

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

Keep search bar visible after displaying placeholder #32

Open douglas-srs opened 6 years ago

douglas-srs commented 6 years ago

I have a search bar in my tableview which refreshes the content as the user types but if the search query is not found the "NoResultsPlaceholder" is shown and the search bar is automatically hidden, is there a way to make the placeholder show below the search bar?

My search bar is added to the table with this: self.tableView.tableHeaderView = UISearchBar()

douglas-srs commented 6 years ago

I managed to preserve the headerView with my search bar by extending the TableView class

class SWTableView: TableView {

    private static var customTheme: PlaceholdersProvider {
        var style = PlaceholderStyle()

        style.shouldShowTableViewHeader = true

        let loading = Placeholder(data: .loading, style: style, key: .loadingKey)

        let error = Placeholder(data: .error, style: style, key: .errorKey)

        let noResults = Placeholder(data: .noResults, style: style, key: .noResultsKey)

        let noConnection = Placeholder(data: .noConnection, style: style, key: .noConnectionKey)

        let placeholdersProvider = PlaceholdersProvider(loading: loading, error: error,
                                                        noResults: noResults, noConnection: noConnection)

        return placeholdersProvider
    }

    override func customSetup() {
        placeholdersProvider = SWTableView.customTheme
    }

}

But now the placeholder content is half visible because the keyboard is visible, is there anyway to make the placeholder move up when the keyboard is visible?