From fb374e6caa04d37e8f863ad52496ec02c115b26b Mon Sep 17 00:00:00 2001 From: TalkingJourney Date: Sat, 13 Apr 2019 21:04:37 +0800 Subject: [PATCH] add ignore tableview sections --- SCIndexView.podspec | 4 +- SCIndexView/SCIndexView.h | 3 + SCIndexView/SCIndexView.m | 31 +++- SCIndexView/UITableView+SCIndexView.h | 3 + SCIndexView/UITableView+SCIndexView.m | 13 ++ .../SCIndexViewDemo.xcodeproj/project.pbxproj | 16 +- .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../IgnoreSectionsIndexes.plist | 174 ++++++++++++++++++ .../SCIndexViewDemo/SCIndexViewController.h | 2 +- .../SCIndexViewDemo/SCIndexViewController.m | 24 +-- .../SCIndexViewDemo/ViewController.m | 16 +- 11 files changed, 255 insertions(+), 39 deletions(-) create mode 100644 SCIndexViewDemo/SCIndexViewDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 SCIndexViewDemo/SCIndexViewDemo/IgnoreSectionsIndexes.plist diff --git a/SCIndexView.podspec b/SCIndexView.podspec index 0d98c27..e4f50f2 100644 --- a/SCIndexView.podspec +++ b/SCIndexView.podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |s| s.name = "SCIndexView" - s.version = "2.1.1" + s.version = "2.2.0" 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.1.1" } + s.source = { :git => "https://github.com/TalkingJourney/SCIndexView.git", :tag => "2.2.0" } s.source_files = "SCIndexView/**/*.{h,m}" s.public_header_files = "SCIndexView/**/*.h" diff --git a/SCIndexView/SCIndexView.h b/SCIndexView/SCIndexView.h index 5db6b66..4515a84 100644 --- a/SCIndexView/SCIndexView.h +++ b/SCIndexView/SCIndexView.h @@ -41,6 +41,9 @@ // tableView在NavigationBar上是否半透明 @property (nonatomic, assign) BOOL translucentForTableViewInNavigationBar; +// tableView从第几个section开始使用索引 Default = 0 +@property (nonatomic, assign) NSUInteger startSection; + // 索引视图的配置 @property (nonatomic, strong, readonly) SCIndexViewConfiguration *configuration; diff --git a/SCIndexView/SCIndexView.m b/SCIndexView/SCIndexView.m index df5a6a8..d8a615a 100644 --- a/SCIndexView/SCIndexView.m +++ b/SCIndexView/SCIndexView.m @@ -156,7 +156,7 @@ - (void)configCurrentSection currentSection = firstVisibleSection; } else { insetHeight = UIApplication.sharedApplication.statusBarFrame.size.height + 44; - for (NSInteger section = firstVisibleSection; section < self.subTextLayers.count; section++) { + for (NSInteger section = firstVisibleSection; section < self.tableView.numberOfSections; section++) { CGRect sectionFrame = [self.tableView rectForSection:section]; if (sectionFrame.origin.y + sectionFrame.size.height - self.tableView.contentOffset.y >= insetHeight) { currentSection = section; @@ -165,15 +165,19 @@ - (void)configCurrentSection } } + BOOL selectSearchLayer = NO; if (currentSection == 0 && self.searchLayer) { CGRect sectionFrame = [self.tableView rectForSection:currentSection]; - BOOL selectSearchLayer = (sectionFrame.origin.y - self.tableView.contentOffset.y - insetHeight) > 0; - if (selectSearchLayer) { - currentSection = SCIndexViewSearchSection; - } + selectSearchLayer = (sectionFrame.origin.y - self.tableView.contentOffset.y - insetHeight) > 0; + } + + if (selectSearchLayer) { + currentSection = SCIndexViewSearchSection; + } + else { + currentSection = currentSection - self.startSection; } - if (currentSection < 0 && currentSection != SCIndexViewSearchSection) return; self.currentSection = currentSection; } @@ -223,7 +227,7 @@ - (void)onActionWithDidSelect CGFloat insetHeight = self.translucentForTableViewInNavigationBar ? UIApplication.sharedApplication.statusBarFrame.size.height + 44 : 0; [self.tableView setContentOffset:CGPointMake(0, -insetHeight) animated:NO]; } else { - NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:self.currentSection]; + NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:self.currentSection + self.startSection]; [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO]; } @@ -450,15 +454,24 @@ - (void)setDataSource:(NSArray *)dataSource - (void)setCurrentSection:(NSInteger)currentSection { + if (currentSection == _currentSection) return; if ((currentSection < 0 && currentSection != SCIndexViewSearchSection) - || currentSection >= (NSInteger)self.subTextLayers.count - || currentSection == _currentSection) return; + || currentSection >= (NSInteger)self.subTextLayers.count) { + [self refreshTextLayer:NO]; + return; + } [self refreshTextLayer:NO]; _currentSection = currentSection; [self refreshTextLayer:YES]; } +- (void)setStartSection:(NSUInteger)startSection { + if (_startSection == startSection) return; + _startSection = startSection; + [self configCurrentSection]; +} + - (NSMutableArray *)subTextLayers { if (!_subTextLayers) { diff --git a/SCIndexView/UITableView+SCIndexView.h b/SCIndexView/UITableView+SCIndexView.h index fe7dac7..b8577ce 100644 --- a/SCIndexView/UITableView+SCIndexView.h +++ b/SCIndexView/UITableView+SCIndexView.h @@ -33,6 +33,9 @@ // tableView在NavigationBar上是否半透明 @property (nonatomic, assign) BOOL sc_translucentForTableViewInNavigationBar; +// tableView从第几个section开始使用索引 Default = 0 +@property (nonatomic, assign) NSUInteger sc_startSection; + // 索引视图的配置 @property (nonatomic, strong) SCIndexViewConfiguration *sc_indexViewConfiguration; diff --git a/SCIndexView/UITableView+SCIndexView.m b/SCIndexView/UITableView+SCIndexView.m index 5e1741a..25bb916 100644 --- a/SCIndexView/UITableView+SCIndexView.m +++ b/SCIndexView/UITableView+SCIndexView.m @@ -168,6 +168,7 @@ - (void)setSc_indexViewDataSource:(NSArray *)sc_indexViewDataSource if (!self.sc_indexView && self.superview) { SCIndexView *indexView = [[SCIndexView alloc] initWithTableView:self configuration:self.sc_indexViewConfiguration]; indexView.translucentForTableViewInNavigationBar = self.sc_translucentForTableViewInNavigationBar; + indexView.startSection = self.sc_startSection; indexView.delegate = self; [self.superview addSubview:indexView]; @@ -177,4 +178,16 @@ - (void)setSc_indexViewDataSource:(NSArray *)sc_indexViewDataSource self.sc_indexView.dataSource = sc_indexViewDataSource.copy; } +- (NSUInteger)sc_startSection { + NSNumber *number = objc_getAssociatedObject(self, @selector(sc_startSection)); + return number.unsignedIntegerValue; +} + +- (void)setSc_startSection:(NSUInteger)sc_startSection { + if (self.sc_startSection == sc_startSection) return; + + objc_setAssociatedObject(self, @selector(sc_startSection), @(sc_startSection), OBJC_ASSOCIATION_RETAIN_NONATOMIC); + self.sc_indexView.startSection = sc_startSection; +} + @end diff --git a/SCIndexViewDemo/SCIndexViewDemo.xcodeproj/project.pbxproj b/SCIndexViewDemo/SCIndexViewDemo.xcodeproj/project.pbxproj index 8700e59..5241eb9 100644 --- a/SCIndexViewDemo/SCIndexViewDemo.xcodeproj/project.pbxproj +++ b/SCIndexViewDemo/SCIndexViewDemo.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 1A3B567F2009F2D30073C98F /* YYClassInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A3B567C2009F2D30073C98F /* YYClassInfo.m */; }; B874C548200A53CB0040DA53 /* SCIndexViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B874C547200A53CB0040DA53 /* SCIndexViewController.m */; }; B874C54E200F83770040DA53 /* UITableView+SCIndexView.m in Sources */ = {isa = PBXBuildFile; fileRef = B874C54D200F83770040DA53 /* UITableView+SCIndexView.m */; }; + B88578D0226208CD008EF8C9 /* IgnoreSectionsIndexes.plist in Resources */ = {isa = PBXBuildFile; fileRef = B88578CF226208CD008EF8C9 /* IgnoreSectionsIndexes.plist */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -50,6 +51,7 @@ B874C547200A53CB0040DA53 /* SCIndexViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SCIndexViewController.m; sourceTree = ""; }; B874C54C200F83770040DA53 /* UITableView+SCIndexView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UITableView+SCIndexView.h"; sourceTree = ""; }; B874C54D200F83770040DA53 /* UITableView+SCIndexView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UITableView+SCIndexView.m"; sourceTree = ""; }; + B88578CF226208CD008EF8C9 /* IgnoreSectionsIndexes.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = IgnoreSectionsIndexes.plist; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -85,6 +87,7 @@ children = ( 1A3B56782009F2D30073C98F /* YYModel */, 1A3B56732009F0B40073C98F /* Indexes.plist */, + B88578CF226208CD008EF8C9 /* IgnoreSectionsIndexes.plist */, 1A3B56752009F0B40073C98F /* SectionItem.h */, 1A3B56742009F0B40073C98F /* SectionItem.m */, 1A3B56412009EE370073C98F /* AppDelegate.h */, @@ -159,7 +162,7 @@ TargetAttributes = { 1A3B563D2009EE370073C98F = { CreatedOnToolsVersion = 9.2; - ProvisioningStyle = Manual; + ProvisioningStyle = Automatic; }; }; }; @@ -190,6 +193,7 @@ 1A3B564B2009EE370073C98F /* Assets.xcassets in Resources */, 1A3B56492009EE370073C98F /* Main.storyboard in Resources */, 1A3B56762009F0B40073C98F /* Indexes.plist in Resources */, + B88578D0226208CD008EF8C9 /* IgnoreSectionsIndexes.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -343,9 +347,10 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CODE_SIGN_STYLE = Manual; - DEVELOPMENT_TEAM = ""; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 3J3Z9KKCQS; INFOPLIST_FILE = SCIndexViewDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -360,9 +365,10 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CODE_SIGN_STYLE = Manual; - DEVELOPMENT_TEAM = ""; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 3J3Z9KKCQS; INFOPLIST_FILE = SCIndexViewDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; diff --git a/SCIndexViewDemo/SCIndexViewDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/SCIndexViewDemo/SCIndexViewDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/SCIndexViewDemo/SCIndexViewDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/SCIndexViewDemo/SCIndexViewDemo/IgnoreSectionsIndexes.plist b/SCIndexViewDemo/SCIndexViewDemo/IgnoreSectionsIndexes.plist new file mode 100644 index 0000000..0702372 --- /dev/null +++ b/SCIndexViewDemo/SCIndexViewDemo/IgnoreSectionsIndexes.plist @@ -0,0 +1,174 @@ + + + + + + title + Ignore_a + items + + Ignore-------1 + Ignore-------2 + Ignore-------3 + Ignore-------4 + Ignore-------5 + + + + title + Ignore_b + items + + Ignore-------1 + Ignore-------2 + Ignore-------3 + Ignore-------4 + Ignore-------5 + + + + title + Ignore_c + items + + Ignore-------1 + Ignore-------2 + Ignore-------3 + Ignore-------4 + Ignore-------5 + + + + title + A + items + + A------------1 + A------------2 + A------------3 + A------------4 + A------------5 + + + + title + B + items + + B------------1 + B------------2 + B------------3 + B------------4 + B------------5 + + + + title + C + items + + C------------1 + C------------2 + C------------3 + C------------4 + C------------5 + + + + title + D + items + + D------------1 + D------------2 + D------------3 + D------------4 + D------------5 + + + + title + E + items + + E------------1 + E------------2 + E------------3 + E------------4 + E------------5 + + + + title + F + items + + F------------1 + F------------2 + F------------3 + F------------4 + F------------5 + + + + title + G + items + + G------------1 + G------------2 + G------------3 + G------------4 + G------------5 + + + + title + H + items + + H------------1 + H------------2 + H------------3 + H------------4 + H------------5 + + + + title + I + items + + I------------1 + I------------2 + I------------3 + I------------4 + I------------5 + + + + title + J + items + + J------------1 + J------------2 + J------------3 + J------------4 + J------------5 + + + + title + K + items + + K------------1 + K------------2 + K------------3 + K------------4 + K------------5 + + + + diff --git a/SCIndexViewDemo/SCIndexViewDemo/SCIndexViewController.h b/SCIndexViewDemo/SCIndexViewDemo/SCIndexViewController.h index bef6795..c371781 100644 --- a/SCIndexViewDemo/SCIndexViewDemo/SCIndexViewController.h +++ b/SCIndexViewDemo/SCIndexViewDemo/SCIndexViewController.h @@ -4,7 +4,7 @@ @interface SCIndexViewController : UIViewController -@property (nonatomic, assign) SCIndexViewStyle indexViewStyle; +@property (nonatomic, assign) BOOL ignoreSections; @property (nonatomic, assign) BOOL hasSearch; @end diff --git a/SCIndexViewDemo/SCIndexViewDemo/SCIndexViewController.m b/SCIndexViewDemo/SCIndexViewDemo/SCIndexViewController.m index d1ef7eb..5e9c9f2 100644 --- a/SCIndexViewDemo/SCIndexViewDemo/SCIndexViewController.m +++ b/SCIndexViewDemo/SCIndexViewDemo/SCIndexViewController.m @@ -20,18 +20,7 @@ @implementation SCIndexViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; - switch (self.indexViewStyle) { - case SCIndexViewStyleDefault: - self.title = @"指向点类型"; - break; - - case SCIndexViewStyleCenterToast: - self.title = @"中心提示弹层"; - break; - - default: - break; - } + self.title = self.ignoreSections ? @"忽略三个sections" : @"不忽略sections"; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(onActionWithRightBarButton)]; self.translucent = YES; @@ -39,11 +28,17 @@ - (void)viewDidLoad { [self.view addSubview:self.tableView]; dispatch_async(dispatch_get_global_queue(0, 0), ^{ - NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Indexes" ofType:@"plist"]; + NSString *plistName = self.ignoreSections ? @"IgnoreSectionsIndexes" : @"Indexes"; + NSString *plistPath = [[NSBundle mainBundle] pathForResource:plistName ofType:@"plist"]; NSArray *tableViewDataSource = [NSArray yy_modelArrayWithClass:SectionItem.class json:[NSArray arrayWithContentsOfFile:plistPath]]; NSMutableArray *indexViewDataSource = [NSMutableArray array]; + NSUInteger startSection = 0; for (SectionItem *item in tableViewDataSource) { + if ([item.title hasPrefix:@"Ignore"]) { + startSection++; + continue; + } [indexViewDataSource addObject:item.title]; } dispatch_sync(dispatch_get_main_queue(), ^{ @@ -54,6 +49,7 @@ - (void)viewDidLoad { [indexViewDataSource insertObject:UITableViewIndexSearch atIndex:0]; } self.tableView.sc_indexViewDataSource = indexViewDataSource.copy; + self.tableView.sc_startSection = startSection; }); }); } @@ -117,7 +113,7 @@ - (UITableView *)tableView self.tableView.tableHeaderView = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 60)]; } - SCIndexViewConfiguration *configuration = [SCIndexViewConfiguration configurationWithIndexViewStyle:self.indexViewStyle]; + SCIndexViewConfiguration *configuration = [SCIndexViewConfiguration configuration]; _tableView.sc_indexViewConfiguration = configuration; _tableView.sc_translucentForTableViewInNavigationBar = self.translucent; } diff --git a/SCIndexViewDemo/SCIndexViewDemo/ViewController.m b/SCIndexViewDemo/SCIndexViewDemo/ViewController.m index ac722b3..af9e277 100644 --- a/SCIndexViewDemo/SCIndexViewDemo/ViewController.m +++ b/SCIndexViewDemo/SCIndexViewDemo/ViewController.m @@ -25,7 +25,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath case 0: { SCIndexViewController *indexViewController = [SCIndexViewController new]; - indexViewController.indexViewStyle = SCIndexViewStyleDefault; + indexViewController.ignoreSections = NO; indexViewController.hasSearch = YES; viewController = indexViewController; } @@ -34,7 +34,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath case 1: { SCIndexViewController *indexViewController = [SCIndexViewController new]; - indexViewController.indexViewStyle = SCIndexViewStyleCenterToast; + indexViewController.ignoreSections = YES; indexViewController.hasSearch = YES; viewController = indexViewController; } @@ -43,7 +43,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath case 2: { SCIndexViewController *indexViewController = [SCIndexViewController new]; - indexViewController.indexViewStyle = SCIndexViewStyleDefault; + indexViewController.ignoreSections = NO; viewController = indexViewController; } break; @@ -51,7 +51,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath case 3: { SCIndexViewController *indexViewController = [SCIndexViewController new]; - indexViewController.indexViewStyle = SCIndexViewStyleCenterToast; + indexViewController.ignoreSections = YES; viewController = indexViewController; } break; @@ -76,28 +76,28 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N switch (indexPath.row) { case 0: { - cell.textLabel.text = @"指向点类型"; + cell.textLabel.text = @"不忽略sections"; cell.detailTextLabel.text = @"有搜索"; } break; case 1: { - cell.textLabel.text = @"中心提示弹层"; + cell.textLabel.text = @"忽略三个sections"; cell.detailTextLabel.text = @"有搜索"; } break; case 2: { - cell.textLabel.text = @"指向点类型"; + cell.textLabel.text = @"不忽略sections"; cell.detailTextLabel.text = @"无搜索"; } break; case 3: { - cell.textLabel.text = @"中心提示弹层"; + cell.textLabel.text = @"忽略三个sections"; cell.detailTextLabel.text = @"无搜索"; } break;