From 32e0743f3924d1c1c5bf34bc93fe36e2f64b3c34 Mon Sep 17 00:00:00 2001 From: Madalina Ardelean Date: Wed, 20 Jan 2016 15:19:34 +0200 Subject: [PATCH] Add no content view when all the cells get deleted --- BIObjCHelpers/Views/TableView/BITableView.m | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/BIObjCHelpers/Views/TableView/BITableView.m b/BIObjCHelpers/Views/TableView/BITableView.m index d3a7b75..fc3c4fa 100644 --- a/BIObjCHelpers/Views/TableView/BITableView.m +++ b/BIObjCHelpers/Views/TableView/BITableView.m @@ -91,6 +91,20 @@ - (void)setTableFooterView:(UIView *)tableFooterView { }]; } +- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation { + [super deleteRowsAtIndexPaths:indexPaths withRowAnimation:animation]; + if ([self BI_totalNumberOfRows] == 0 && !self.visibleAdditionalView) { + [self addAdditionalNoContentView]; + } +} + +- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation { + [super insertRowsAtIndexPaths:indexPaths withRowAnimation:animation]; + if ([self BI_totalNumberOfRows] != 0 && self.visibleAdditionalView) { + [self removeVisibleAdditionalView]; + } +} + #pragma mark - Public methods - (void)triggerPullToRefresh { @@ -244,6 +258,19 @@ - (void)BI_createInfiniteScrollingActivityIndicatorContainer { } } +- (NSInteger)BI_totalNumberOfRows { + NSInteger numberOfSections = 1; + if ([self.dataSource respondsToSelector:@selector(numberOfSectionsInTableView:)]) { + numberOfSections = [self.dataSource numberOfSectionsInTableView:self]; + } + + NSInteger totalNumberOfRows = 0; + for (NSInteger sectionIndex = 0; sectionIndex < numberOfSections; sectionIndex++) { + totalNumberOfRows += [self.dataSource tableView:self numberOfRowsInSection:sectionIndex]; + } + return totalNumberOfRows; +} + @end