Skip to content

Commit

Permalink
add ignore tableview sections
Browse files Browse the repository at this point in the history
  • Loading branch information
TalkingJourney committed Apr 13, 2019
1 parent 6ed8d43 commit fb374e6
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 39 deletions.
4 changes: 2 additions & 2 deletions SCIndexView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand All @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions SCIndexView/SCIndexView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
31 changes: 22 additions & 9 deletions SCIndexView/SCIndexView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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];
}

Expand Down Expand Up @@ -450,15 +454,24 @@ - (void)setDataSource:(NSArray<NSString *> *)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) {
Expand Down
3 changes: 3 additions & 0 deletions SCIndexView/UITableView+SCIndexView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 13 additions & 0 deletions SCIndexView/UITableView+SCIndexView.m
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ - (void)setSc_indexViewDataSource:(NSArray<NSString *> *)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];

Expand All @@ -177,4 +178,16 @@ - (void)setSc_indexViewDataSource:(NSArray<NSString *> *)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
16 changes: 11 additions & 5 deletions SCIndexViewDemo/SCIndexViewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -50,6 +51,7 @@
B874C547200A53CB0040DA53 /* SCIndexViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SCIndexViewController.m; sourceTree = "<group>"; };
B874C54C200F83770040DA53 /* UITableView+SCIndexView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UITableView+SCIndexView.h"; sourceTree = "<group>"; };
B874C54D200F83770040DA53 /* UITableView+SCIndexView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UITableView+SCIndexView.m"; sourceTree = "<group>"; };
B88578CF226208CD008EF8C9 /* IgnoreSectionsIndexes.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = IgnoreSectionsIndexes.plist; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -85,6 +87,7 @@
children = (
1A3B56782009F2D30073C98F /* YYModel */,
1A3B56732009F0B40073C98F /* Indexes.plist */,
B88578CF226208CD008EF8C9 /* IgnoreSectionsIndexes.plist */,
1A3B56752009F0B40073C98F /* SectionItem.h */,
1A3B56742009F0B40073C98F /* SectionItem.m */,
1A3B56412009EE370073C98F /* AppDelegate.h */,
Expand Down Expand Up @@ -159,7 +162,7 @@
TargetAttributes = {
1A3B563D2009EE370073C98F = {
CreatedOnToolsVersion = 9.2;
ProvisioningStyle = Manual;
ProvisioningStyle = Automatic;
};
};
};
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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";
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
174 changes: 174 additions & 0 deletions SCIndexViewDemo/SCIndexViewDemo/IgnoreSectionsIndexes.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>title</key>
<string>Ignore_a</string>
<key>items</key>
<array>
<string>Ignore-------1</string>
<string>Ignore-------2</string>
<string>Ignore-------3</string>
<string>Ignore-------4</string>
<string>Ignore-------5</string>
</array>
</dict>
<dict>
<key>title</key>
<string>Ignore_b</string>
<key>items</key>
<array>
<string>Ignore-------1</string>
<string>Ignore-------2</string>
<string>Ignore-------3</string>
<string>Ignore-------4</string>
<string>Ignore-------5</string>
</array>
</dict>
<dict>
<key>title</key>
<string>Ignore_c</string>
<key>items</key>
<array>
<string>Ignore-------1</string>
<string>Ignore-------2</string>
<string>Ignore-------3</string>
<string>Ignore-------4</string>
<string>Ignore-------5</string>
</array>
</dict>
<dict>
<key>title</key>
<string>A</string>
<key>items</key>
<array>
<string>A------------1</string>
<string>A------------2</string>
<string>A------------3</string>
<string>A------------4</string>
<string>A------------5</string>
</array>
</dict>
<dict>
<key>title</key>
<string>B</string>
<key>items</key>
<array>
<string>B------------1</string>
<string>B------------2</string>
<string>B------------3</string>
<string>B------------4</string>
<string>B------------5</string>
</array>
</dict>
<dict>
<key>title</key>
<string>C</string>
<key>items</key>
<array>
<string>C------------1</string>
<string>C------------2</string>
<string>C------------3</string>
<string>C------------4</string>
<string>C------------5</string>
</array>
</dict>
<dict>
<key>title</key>
<string>D</string>
<key>items</key>
<array>
<string>D------------1</string>
<string>D------------2</string>
<string>D------------3</string>
<string>D------------4</string>
<string>D------------5</string>
</array>
</dict>
<dict>
<key>title</key>
<string>E</string>
<key>items</key>
<array>
<string>E------------1</string>
<string>E------------2</string>
<string>E------------3</string>
<string>E------------4</string>
<string>E------------5</string>
</array>
</dict>
<dict>
<key>title</key>
<string>F</string>
<key>items</key>
<array>
<string>F------------1</string>
<string>F------------2</string>
<string>F------------3</string>
<string>F------------4</string>
<string>F------------5</string>
</array>
</dict>
<dict>
<key>title</key>
<string>G</string>
<key>items</key>
<array>
<string>G------------1</string>
<string>G------------2</string>
<string>G------------3</string>
<string>G------------4</string>
<string>G------------5</string>
</array>
</dict>
<dict>
<key>title</key>
<string>H</string>
<key>items</key>
<array>
<string>H------------1</string>
<string>H------------2</string>
<string>H------------3</string>
<string>H------------4</string>
<string>H------------5</string>
</array>
</dict>
<dict>
<key>title</key>
<string>I</string>
<key>items</key>
<array>
<string>I------------1</string>
<string>I------------2</string>
<string>I------------3</string>
<string>I------------4</string>
<string>I------------5</string>
</array>
</dict>
<dict>
<key>title</key>
<string>J</string>
<key>items</key>
<array>
<string>J------------1</string>
<string>J------------2</string>
<string>J------------3</string>
<string>J------------4</string>
<string>J------------5</string>
</array>
</dict>
<dict>
<key>title</key>
<string>K</string>
<key>items</key>
<array>
<string>K------------1</string>
<string>K------------2</string>
<string>K------------3</string>
<string>K------------4</string>
<string>K------------5</string>
</array>
</dict>
</array>
</plist>
2 changes: 1 addition & 1 deletion SCIndexViewDemo/SCIndexViewDemo/SCIndexViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@interface SCIndexViewController : UIViewController

@property (nonatomic, assign) SCIndexViewStyle indexViewStyle;
@property (nonatomic, assign) BOOL ignoreSections;
@property (nonatomic, assign) BOOL hasSearch;

@end
Loading

0 comments on commit fb374e6

Please sign in to comment.