Skip to content

Commit

Permalink
Fixing issue: TableView Footer/Header views are not preserved if set …
Browse files Browse the repository at this point in the history
…programmatically
  • Loading branch information
HamzaGhazouani committed Aug 28, 2017
1 parent 2377511 commit 38b1965
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,10 @@
# Change Log
All notable changes to this project will be documented in this file.

## [0.2.5](https://github.com/HamzaGhazouani/HGPlaceholders/releases/tag/0.2.4)

* Fixing issue: TableView Footer/Header views are not preserved if set programmatically (iOS 9)

## [0.2.4](https://github.com/HamzaGhazouani/HGPlaceholders/releases/tag/0.2.4)

* Fixing UICollectionFlowLayout issue (iOS 9)
Expand Down
2 changes: 1 addition & 1 deletion HGPlaceholders.podspec
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'HGPlaceholders'
s.version = '0.2.4'
s.version = '0.2.5'
s.summary = 'Nice library to show placeholders and Empty States for any UITableView/UICollectionView in your project'

# This description is used to generate tags and improve search results.
Expand Down
30 changes: 28 additions & 2 deletions HGPlaceholders/Classes/Views/TableView.swift
Expand Up @@ -63,6 +63,30 @@ open class TableView: UITableView {
}
}

/**
* Returns an accessory view that is displayed above the table.
* The default value is nil. The table header view is different from a section header.
*/
open override var tableHeaderView: UIView? {
didSet {
if tableHeaderView == nil { return }

defaultTableHeaderView = tableHeaderView
}
}

/**
* Returns an accessory view that is displayed below the table.
* The default value is nil. The table footer view is different from a section footer.
*/
open override var tableFooterView: UIView? {
didSet {
if tableFooterView == nil { return }

defaultTableFooterView = tableFooterView
}
}

// MARK: - Private properties

/// The defaultDataSource is used to allow to go back to the initial data source of the table view after switching to a placeholder data source
Expand All @@ -77,12 +101,12 @@ open class TableView: UITableView {
/// The defaultAlwaysBounceVertical is used to save the tableview bouncing setup, because, when you switch to a placeholder, the vertical bounce is disabled
fileprivate var defaultAlwaysBounceVertical: Bool!

/// The defaultTableViewHeader is used to save the tableview header when you switch to placeholders
/// The defaultTableViewHeader is used to save the tableview header when you switch to placeholders
fileprivate var defaultTableHeaderView: UIView?

/// The defaultTableViewFooter is used to save the tableview footer when you switch to placeholders
fileprivate var defaultTableFooterView: UIView?

// MARK: - init methods

/**
Expand Down Expand Up @@ -122,8 +146,10 @@ open class TableView: UITableView {

defaultSeparatorStyle = separatorStyle
defaultAlwaysBounceVertical = alwaysBounceVertical

defaultTableHeaderView = tableHeaderView
defaultTableFooterView = tableFooterView

customSetup()
}

Expand Down

0 comments on commit 38b1965

Please sign in to comment.