diff --git a/SCIndexView.podspec b/SCIndexView.podspec index 07239d3..f9cbb67 100644 --- a/SCIndexView.podspec +++ b/SCIndexView.podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |s| s.name = "SCIndexView" - s.version = "2.2.1" + s.version = "2.2.2" s.summary = "SCIndexView provide a index view." s.description = "SCIndexView provide a index view like Wechat. It is very easy." @@ -20,7 +20,7 @@ Pod::Spec.new do |s| s.platform = :ios, "7.0" - s.source = { :git => "https://github.com/TalkingJourney/SCIndexView.git", :tag => "2.2.1" } + s.source = { :git => "https://github.com/TalkingJourney/SCIndexView.git", :tag => "2.2.2" } s.source_files = "SCIndexView/**/*.{h,m}" s.public_header_files = "SCIndexView/**/*.h" diff --git a/SCIndexView/SCIndexView.m b/SCIndexView/SCIndexView.m index 37f560f..2e124b6 100644 --- a/SCIndexView/SCIndexView.m +++ b/SCIndexView/SCIndexView.m @@ -202,12 +202,11 @@ - (void)onActionWithDidSelect } else { NSInteger currentSection = self.currentSection + self.startSection; if (currentSection >= 0 && currentSection < self.tableView.numberOfSections) { - CGRect rect = [self.tableView rectForSection:currentSection]; - CGFloat offsetY = rect.origin.y - insetTop; - CGFloat offsetMaxY = self.tableView.contentSize.height + self.tableView.contentInset.bottom - self.tableView.bounds.size.height; - CGPoint contentOffset = self.tableView.contentOffset; - contentOffset.y = offsetY < offsetMaxY ? offsetY : offsetMaxY; - self.tableView.contentOffset = contentOffset; + NSUInteger rowCountInSection = [self.tableView numberOfRowsInSection:currentSection]; + if (rowCountInSection > 0) { + NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:currentSection]; + [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO]; + } } } @@ -276,7 +275,14 @@ - (CAShapeLayer *)createSearchLayer - (void)showIndicator:(BOOL)animated { - if (self.currentSection < 0 || self.currentSection >= (NSInteger)self.subTextLayers.count) return; + if (self.currentSection >= (NSInteger)self.subTextLayers.count) return; + + if (self.currentSection < 0) { + if (self.currentSection == SCIndexViewSearchSection) { + [self hideIndicator:animated]; + } + return; + } CATextLayer *textLayer = self.subTextLayers[self.currentSection]; if (self.configuration.indexViewStyle == SCIndexViewStyleDefault) {