Skip to content

Commit 3d7bc17

Browse files
committed
Merge pull request #51 from andrewsardone/empty-view-ordering
Fix empty view setup if configured before parent view
2 parents 2321bc7 + 4073db6 commit 3d7bc17

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

Example/ExampleSSDataSourcesTests/SSBaseDataSourceTests.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,36 @@ - (void)testBuildingArrayOfIndexPathsWithIndexSet
189189
expect(indexPaths).to.equal(@[[NSIndexPath indexPathForRow:1 inSection:0]]);
190190
}
191191

192+
#pragma mark Empty View
193+
194+
- (void)testBasicEmptyViewVisibility
195+
{
196+
// hidden empty view
197+
SSArrayDataSource *arrayDataSource = [[SSArrayDataSource alloc] initWithItems:@[ @"item" ]];
198+
arrayDataSource.tableView = tableView;
199+
arrayDataSource.emptyView = [UIView new];
200+
expect(arrayDataSource.emptyView.hidden).to.beTruthy();
201+
202+
// visible empty view
203+
[arrayDataSource removeAllItems];
204+
expect(arrayDataSource.emptyView.hidden).to.beFalsy();
205+
}
206+
207+
- (void)testEmptyViewSetUpIsNotDependentOnParentViewConfiguration
208+
{
209+
// The intent is to ensure that you can set up your emptyView *before* you
210+
// assign the data source’s table or collection view.
211+
SSArrayDataSource *arrayDataSource;
212+
213+
arrayDataSource = [[SSArrayDataSource alloc] initWithItems:@[]];
214+
arrayDataSource.emptyView = [UIView new];
215+
arrayDataSource.tableView = tableView;
216+
expect(arrayDataSource.emptyView.hidden).to.beFalsy();
217+
218+
arrayDataSource = [[SSArrayDataSource alloc] initWithItems:@[]];
219+
arrayDataSource.emptyView = [UIView new];
220+
arrayDataSource.collectionView = collectionView;
221+
expect(arrayDataSource.emptyView.hidden).to.beFalsy();
222+
}
223+
192224
@end

SSDataSources/SSBaseDataSource.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ - (void)setTableView:(UITableView *)tableView {
104104
if (tableView) {
105105
tableView.dataSource = self;
106106
}
107+
108+
[self _updateEmptyView];
107109
}
108110

109111
- (void)setCollectionView:(UICollectionView *)collectionView {
@@ -112,6 +114,8 @@ - (void)setCollectionView:(UICollectionView *)collectionView {
112114
if (collectionView) {
113115
collectionView.dataSource = self;
114116
}
117+
118+
[self _updateEmptyView];
115119
}
116120

117121
#pragma mark - UITableViewDataSource

0 commit comments

Comments
 (0)