├── CollapseTableView.podspec ├── CollapseTableView.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── serhii_kharauzov.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── serhii_kharauzov.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist ├── CollapseTableView ├── CollapseTableView.h ├── Info.plist └── Source │ ├── CollapseSectionHeader.swift │ └── CollapseTableView.swift ├── CollapseTableViewDemo ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── arrow_down.imageset │ │ ├── Contents.json │ │ └── arrow_down.pdf ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── ReusableView.swift ├── SectionHeaderView.swift ├── SectionHeaderView.xib └── ViewController.swift ├── LICENSE ├── README.md └── collapseTableViewDemo.gif /CollapseTableView.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | 4 | s.platform = :ios 5 | s.ios.deployment_target = '10.0' 6 | s.name = "CollapseTableView" 7 | s.summary = "CollapseTableView enables to expand sections with cells inside." 8 | s.requires_arc = true 9 | s.version = "1.0.3" 10 | s.license = { :type => "MIT", :file => "LICENSE" } 11 | s.author = { "Serhii Kharauzov" => "serhii.kharauzov@gmail.com" } 12 | s.homepage = "https://github.com/Kharauzov/CollapseTableView" 13 | s.source = { :git => "https://github.com/Kharauzov/CollapseTableView.git", 14 | :tag => s.version } 15 | s.framework = "UIKit" 16 | s.source_files = "CollapseTableView/**/*.{swift}" 17 | s.swift_version = "5.0" 18 | 19 | end 20 | -------------------------------------------------------------------------------- /CollapseTableView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4901DBBD22ABC747008CC400 /* CollapseSectionHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4901DBBB22ABC747008CC400 /* CollapseSectionHeader.swift */; }; 11 | 4901DBBE22ABC747008CC400 /* CollapseTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4901DBBC22ABC747008CC400 /* CollapseTableView.swift */; }; 12 | 4919EFCE22AC25D400CD5A74 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4919EFCD22AC25D400CD5A74 /* AppDelegate.swift */; }; 13 | 4919EFD022AC25D400CD5A74 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4919EFCF22AC25D400CD5A74 /* ViewController.swift */; }; 14 | 4919EFD322AC25D400CD5A74 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4919EFD122AC25D400CD5A74 /* Main.storyboard */; }; 15 | 4919EFD522AC25D500CD5A74 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4919EFD422AC25D500CD5A74 /* Assets.xcassets */; }; 16 | 4919EFD822AC25D500CD5A74 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4919EFD622AC25D500CD5A74 /* LaunchScreen.storyboard */; }; 17 | 4919EFDF22AC263D00CD5A74 /* SectionHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4919EFDD22AC263D00CD5A74 /* SectionHeaderView.swift */; }; 18 | 4919EFE022AC263D00CD5A74 /* SectionHeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4919EFDE22AC263D00CD5A74 /* SectionHeaderView.xib */; }; 19 | 4919EFE122AC27A200CD5A74 /* CollapseTableView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4922F97122AAE53700967BB5 /* CollapseTableView.framework */; }; 20 | 4919EFE222AC27A200CD5A74 /* CollapseTableView.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4922F97122AAE53700967BB5 /* CollapseTableView.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 21 | 4922F97622AAE53700967BB5 /* CollapseTableView.h in Headers */ = {isa = PBXBuildFile; fileRef = 4922F97422AAE53700967BB5 /* CollapseTableView.h */; settings = {ATTRIBUTES = (Public, ); }; }; 22 | 49F918182312E1BB0075D644 /* ReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49F918172312E1BB0075D644 /* ReusableView.swift */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXContainerItemProxy section */ 26 | 4919EFE322AC27A200CD5A74 /* PBXContainerItemProxy */ = { 27 | isa = PBXContainerItemProxy; 28 | containerPortal = 4922F96822AAE53700967BB5 /* Project object */; 29 | proxyType = 1; 30 | remoteGlobalIDString = 4922F97022AAE53700967BB5; 31 | remoteInfo = CollapseTableView; 32 | }; 33 | /* End PBXContainerItemProxy section */ 34 | 35 | /* Begin PBXCopyFilesBuildPhase section */ 36 | 4919EFE522AC27A200CD5A74 /* Embed Frameworks */ = { 37 | isa = PBXCopyFilesBuildPhase; 38 | buildActionMask = 2147483647; 39 | dstPath = ""; 40 | dstSubfolderSpec = 10; 41 | files = ( 42 | 4919EFE222AC27A200CD5A74 /* CollapseTableView.framework in Embed Frameworks */, 43 | ); 44 | name = "Embed Frameworks"; 45 | runOnlyForDeploymentPostprocessing = 0; 46 | }; 47 | /* End PBXCopyFilesBuildPhase section */ 48 | 49 | /* Begin PBXFileReference section */ 50 | 4901DBBB22ABC747008CC400 /* CollapseSectionHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollapseSectionHeader.swift; sourceTree = ""; }; 51 | 4901DBBC22ABC747008CC400 /* CollapseTableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollapseTableView.swift; sourceTree = ""; }; 52 | 4919EFCB22AC25D400CD5A74 /* CollapseTableViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CollapseTableViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 53 | 4919EFCD22AC25D400CD5A74 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 54 | 4919EFCF22AC25D400CD5A74 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 55 | 4919EFD222AC25D400CD5A74 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 56 | 4919EFD422AC25D500CD5A74 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 57 | 4919EFD722AC25D500CD5A74 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 58 | 4919EFD922AC25D500CD5A74 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 59 | 4919EFDD22AC263D00CD5A74 /* SectionHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SectionHeaderView.swift; sourceTree = ""; }; 60 | 4919EFDE22AC263D00CD5A74 /* SectionHeaderView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SectionHeaderView.xib; sourceTree = ""; }; 61 | 4922F97122AAE53700967BB5 /* CollapseTableView.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CollapseTableView.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 62 | 4922F97422AAE53700967BB5 /* CollapseTableView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CollapseTableView.h; sourceTree = ""; }; 63 | 4922F97522AAE53700967BB5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 64 | 49F918172312E1BB0075D644 /* ReusableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReusableView.swift; sourceTree = ""; }; 65 | /* End PBXFileReference section */ 66 | 67 | /* Begin PBXFrameworksBuildPhase section */ 68 | 4919EFC822AC25D400CD5A74 /* Frameworks */ = { 69 | isa = PBXFrameworksBuildPhase; 70 | buildActionMask = 2147483647; 71 | files = ( 72 | 4919EFE122AC27A200CD5A74 /* CollapseTableView.framework in Frameworks */, 73 | ); 74 | runOnlyForDeploymentPostprocessing = 0; 75 | }; 76 | 4922F96E22AAE53700967BB5 /* Frameworks */ = { 77 | isa = PBXFrameworksBuildPhase; 78 | buildActionMask = 2147483647; 79 | files = ( 80 | ); 81 | runOnlyForDeploymentPostprocessing = 0; 82 | }; 83 | /* End PBXFrameworksBuildPhase section */ 84 | 85 | /* Begin PBXGroup section */ 86 | 4901DBBA22ABC747008CC400 /* Source */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 4901DBBB22ABC747008CC400 /* CollapseSectionHeader.swift */, 90 | 4901DBBC22ABC747008CC400 /* CollapseTableView.swift */, 91 | ); 92 | path = Source; 93 | sourceTree = ""; 94 | }; 95 | 4919EFCC22AC25D400CD5A74 /* CollapseTableViewDemo */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | 49F918172312E1BB0075D644 /* ReusableView.swift */, 99 | 4919EFCD22AC25D400CD5A74 /* AppDelegate.swift */, 100 | 4919EFDD22AC263D00CD5A74 /* SectionHeaderView.swift */, 101 | 4919EFDE22AC263D00CD5A74 /* SectionHeaderView.xib */, 102 | 4919EFCF22AC25D400CD5A74 /* ViewController.swift */, 103 | 4919EFD122AC25D400CD5A74 /* Main.storyboard */, 104 | 4919EFD422AC25D500CD5A74 /* Assets.xcassets */, 105 | 4919EFD622AC25D500CD5A74 /* LaunchScreen.storyboard */, 106 | 4919EFD922AC25D500CD5A74 /* Info.plist */, 107 | ); 108 | path = CollapseTableViewDemo; 109 | sourceTree = ""; 110 | }; 111 | 4922F96722AAE53700967BB5 = { 112 | isa = PBXGroup; 113 | children = ( 114 | 4922F97322AAE53700967BB5 /* CollapseTableView */, 115 | 4919EFCC22AC25D400CD5A74 /* CollapseTableViewDemo */, 116 | 4922F97222AAE53700967BB5 /* Products */, 117 | ); 118 | sourceTree = ""; 119 | }; 120 | 4922F97222AAE53700967BB5 /* Products */ = { 121 | isa = PBXGroup; 122 | children = ( 123 | 4922F97122AAE53700967BB5 /* CollapseTableView.framework */, 124 | 4919EFCB22AC25D400CD5A74 /* CollapseTableViewDemo.app */, 125 | ); 126 | name = Products; 127 | sourceTree = ""; 128 | }; 129 | 4922F97322AAE53700967BB5 /* CollapseTableView */ = { 130 | isa = PBXGroup; 131 | children = ( 132 | 4901DBBA22ABC747008CC400 /* Source */, 133 | 4922F97422AAE53700967BB5 /* CollapseTableView.h */, 134 | 4922F97522AAE53700967BB5 /* Info.plist */, 135 | ); 136 | path = CollapseTableView; 137 | sourceTree = ""; 138 | }; 139 | /* End PBXGroup section */ 140 | 141 | /* Begin PBXHeadersBuildPhase section */ 142 | 4922F96C22AAE53700967BB5 /* Headers */ = { 143 | isa = PBXHeadersBuildPhase; 144 | buildActionMask = 2147483647; 145 | files = ( 146 | 4922F97622AAE53700967BB5 /* CollapseTableView.h in Headers */, 147 | ); 148 | runOnlyForDeploymentPostprocessing = 0; 149 | }; 150 | /* End PBXHeadersBuildPhase section */ 151 | 152 | /* Begin PBXNativeTarget section */ 153 | 4919EFCA22AC25D400CD5A74 /* CollapseTableViewDemo */ = { 154 | isa = PBXNativeTarget; 155 | buildConfigurationList = 4919EFDC22AC25D500CD5A74 /* Build configuration list for PBXNativeTarget "CollapseTableViewDemo" */; 156 | buildPhases = ( 157 | 4919EFC722AC25D400CD5A74 /* Sources */, 158 | 4919EFC822AC25D400CD5A74 /* Frameworks */, 159 | 4919EFC922AC25D400CD5A74 /* Resources */, 160 | 4919EFE522AC27A200CD5A74 /* Embed Frameworks */, 161 | ); 162 | buildRules = ( 163 | ); 164 | dependencies = ( 165 | 4919EFE422AC27A200CD5A74 /* PBXTargetDependency */, 166 | ); 167 | name = CollapseTableViewDemo; 168 | productName = CollapseTableViewDemo; 169 | productReference = 4919EFCB22AC25D400CD5A74 /* CollapseTableViewDemo.app */; 170 | productType = "com.apple.product-type.application"; 171 | }; 172 | 4922F97022AAE53700967BB5 /* CollapseTableView */ = { 173 | isa = PBXNativeTarget; 174 | buildConfigurationList = 4922F97922AAE53700967BB5 /* Build configuration list for PBXNativeTarget "CollapseTableView" */; 175 | buildPhases = ( 176 | 4922F96C22AAE53700967BB5 /* Headers */, 177 | 4922F96D22AAE53700967BB5 /* Sources */, 178 | 4922F96E22AAE53700967BB5 /* Frameworks */, 179 | 4922F96F22AAE53700967BB5 /* Resources */, 180 | ); 181 | buildRules = ( 182 | ); 183 | dependencies = ( 184 | ); 185 | name = CollapseTableView; 186 | productName = CollapseTableView; 187 | productReference = 4922F97122AAE53700967BB5 /* CollapseTableView.framework */; 188 | productType = "com.apple.product-type.framework"; 189 | }; 190 | /* End PBXNativeTarget section */ 191 | 192 | /* Begin PBXProject section */ 193 | 4922F96822AAE53700967BB5 /* Project object */ = { 194 | isa = PBXProject; 195 | attributes = { 196 | LastSwiftUpdateCheck = 1020; 197 | LastUpgradeCheck = 1020; 198 | ORGANIZATIONNAME = "Serhii Kharauzov"; 199 | TargetAttributes = { 200 | 4919EFCA22AC25D400CD5A74 = { 201 | CreatedOnToolsVersion = 10.2; 202 | }; 203 | 4922F97022AAE53700967BB5 = { 204 | CreatedOnToolsVersion = 10.2; 205 | }; 206 | }; 207 | }; 208 | buildConfigurationList = 4922F96B22AAE53700967BB5 /* Build configuration list for PBXProject "CollapseTableView" */; 209 | compatibilityVersion = "Xcode 9.3"; 210 | developmentRegion = en; 211 | hasScannedForEncodings = 0; 212 | knownRegions = ( 213 | en, 214 | Base, 215 | ); 216 | mainGroup = 4922F96722AAE53700967BB5; 217 | productRefGroup = 4922F97222AAE53700967BB5 /* Products */; 218 | projectDirPath = ""; 219 | projectRoot = ""; 220 | targets = ( 221 | 4922F97022AAE53700967BB5 /* CollapseTableView */, 222 | 4919EFCA22AC25D400CD5A74 /* CollapseTableViewDemo */, 223 | ); 224 | }; 225 | /* End PBXProject section */ 226 | 227 | /* Begin PBXResourcesBuildPhase section */ 228 | 4919EFC922AC25D400CD5A74 /* Resources */ = { 229 | isa = PBXResourcesBuildPhase; 230 | buildActionMask = 2147483647; 231 | files = ( 232 | 4919EFD822AC25D500CD5A74 /* LaunchScreen.storyboard in Resources */, 233 | 4919EFD522AC25D500CD5A74 /* Assets.xcassets in Resources */, 234 | 4919EFD322AC25D400CD5A74 /* Main.storyboard in Resources */, 235 | 4919EFE022AC263D00CD5A74 /* SectionHeaderView.xib in Resources */, 236 | ); 237 | runOnlyForDeploymentPostprocessing = 0; 238 | }; 239 | 4922F96F22AAE53700967BB5 /* Resources */ = { 240 | isa = PBXResourcesBuildPhase; 241 | buildActionMask = 2147483647; 242 | files = ( 243 | ); 244 | runOnlyForDeploymentPostprocessing = 0; 245 | }; 246 | /* End PBXResourcesBuildPhase section */ 247 | 248 | /* Begin PBXSourcesBuildPhase section */ 249 | 4919EFC722AC25D400CD5A74 /* Sources */ = { 250 | isa = PBXSourcesBuildPhase; 251 | buildActionMask = 2147483647; 252 | files = ( 253 | 4919EFD022AC25D400CD5A74 /* ViewController.swift in Sources */, 254 | 4919EFDF22AC263D00CD5A74 /* SectionHeaderView.swift in Sources */, 255 | 4919EFCE22AC25D400CD5A74 /* AppDelegate.swift in Sources */, 256 | 49F918182312E1BB0075D644 /* ReusableView.swift in Sources */, 257 | ); 258 | runOnlyForDeploymentPostprocessing = 0; 259 | }; 260 | 4922F96D22AAE53700967BB5 /* Sources */ = { 261 | isa = PBXSourcesBuildPhase; 262 | buildActionMask = 2147483647; 263 | files = ( 264 | 4901DBBE22ABC747008CC400 /* CollapseTableView.swift in Sources */, 265 | 4901DBBD22ABC747008CC400 /* CollapseSectionHeader.swift in Sources */, 266 | ); 267 | runOnlyForDeploymentPostprocessing = 0; 268 | }; 269 | /* End PBXSourcesBuildPhase section */ 270 | 271 | /* Begin PBXTargetDependency section */ 272 | 4919EFE422AC27A200CD5A74 /* PBXTargetDependency */ = { 273 | isa = PBXTargetDependency; 274 | target = 4922F97022AAE53700967BB5 /* CollapseTableView */; 275 | targetProxy = 4919EFE322AC27A200CD5A74 /* PBXContainerItemProxy */; 276 | }; 277 | /* End PBXTargetDependency section */ 278 | 279 | /* Begin PBXVariantGroup section */ 280 | 4919EFD122AC25D400CD5A74 /* Main.storyboard */ = { 281 | isa = PBXVariantGroup; 282 | children = ( 283 | 4919EFD222AC25D400CD5A74 /* Base */, 284 | ); 285 | name = Main.storyboard; 286 | sourceTree = ""; 287 | }; 288 | 4919EFD622AC25D500CD5A74 /* LaunchScreen.storyboard */ = { 289 | isa = PBXVariantGroup; 290 | children = ( 291 | 4919EFD722AC25D500CD5A74 /* Base */, 292 | ); 293 | name = LaunchScreen.storyboard; 294 | sourceTree = ""; 295 | }; 296 | /* End PBXVariantGroup section */ 297 | 298 | /* Begin XCBuildConfiguration section */ 299 | 4919EFDA22AC25D500CD5A74 /* Debug */ = { 300 | isa = XCBuildConfiguration; 301 | buildSettings = { 302 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 303 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 304 | CODE_SIGN_STYLE = Manual; 305 | DEVELOPMENT_TEAM = ""; 306 | INFOPLIST_FILE = CollapseTableViewDemo/Info.plist; 307 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 308 | LD_RUNPATH_SEARCH_PATHS = ( 309 | "$(inherited)", 310 | "@executable_path/Frameworks", 311 | ); 312 | PRODUCT_BUNDLE_IDENTIFIER = sk.CollapseTableViewDemo; 313 | PRODUCT_NAME = "$(TARGET_NAME)"; 314 | PROVISIONING_PROFILE_SPECIFIER = ""; 315 | SWIFT_VERSION = 5.0; 316 | TARGETED_DEVICE_FAMILY = "1,2"; 317 | }; 318 | name = Debug; 319 | }; 320 | 4919EFDB22AC25D500CD5A74 /* Release */ = { 321 | isa = XCBuildConfiguration; 322 | buildSettings = { 323 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 324 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 325 | CODE_SIGN_STYLE = Manual; 326 | DEVELOPMENT_TEAM = ""; 327 | INFOPLIST_FILE = CollapseTableViewDemo/Info.plist; 328 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 329 | LD_RUNPATH_SEARCH_PATHS = ( 330 | "$(inherited)", 331 | "@executable_path/Frameworks", 332 | ); 333 | PRODUCT_BUNDLE_IDENTIFIER = sk.CollapseTableViewDemo; 334 | PRODUCT_NAME = "$(TARGET_NAME)"; 335 | PROVISIONING_PROFILE_SPECIFIER = ""; 336 | SWIFT_VERSION = 5.0; 337 | TARGETED_DEVICE_FAMILY = "1,2"; 338 | }; 339 | name = Release; 340 | }; 341 | 4922F97722AAE53700967BB5 /* Debug */ = { 342 | isa = XCBuildConfiguration; 343 | buildSettings = { 344 | ALWAYS_SEARCH_USER_PATHS = NO; 345 | CLANG_ANALYZER_NONNULL = YES; 346 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 347 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 348 | CLANG_CXX_LIBRARY = "libc++"; 349 | CLANG_ENABLE_MODULES = YES; 350 | CLANG_ENABLE_OBJC_ARC = YES; 351 | CLANG_ENABLE_OBJC_WEAK = YES; 352 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 353 | CLANG_WARN_BOOL_CONVERSION = YES; 354 | CLANG_WARN_COMMA = YES; 355 | CLANG_WARN_CONSTANT_CONVERSION = YES; 356 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 357 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 358 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 359 | CLANG_WARN_EMPTY_BODY = YES; 360 | CLANG_WARN_ENUM_CONVERSION = YES; 361 | CLANG_WARN_INFINITE_RECURSION = YES; 362 | CLANG_WARN_INT_CONVERSION = YES; 363 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 364 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 365 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 366 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 367 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 368 | CLANG_WARN_STRICT_PROTOTYPES = YES; 369 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 370 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 371 | CLANG_WARN_UNREACHABLE_CODE = YES; 372 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 373 | CODE_SIGN_IDENTITY = "iPhone Developer"; 374 | COPY_PHASE_STRIP = NO; 375 | CURRENT_PROJECT_VERSION = 1; 376 | DEBUG_INFORMATION_FORMAT = dwarf; 377 | ENABLE_STRICT_OBJC_MSGSEND = YES; 378 | ENABLE_TESTABILITY = YES; 379 | GCC_C_LANGUAGE_STANDARD = gnu11; 380 | GCC_DYNAMIC_NO_PIC = NO; 381 | GCC_NO_COMMON_BLOCKS = YES; 382 | GCC_OPTIMIZATION_LEVEL = 0; 383 | GCC_PREPROCESSOR_DEFINITIONS = ( 384 | "DEBUG=1", 385 | "$(inherited)", 386 | ); 387 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 388 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 389 | GCC_WARN_UNDECLARED_SELECTOR = YES; 390 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 391 | GCC_WARN_UNUSED_FUNCTION = YES; 392 | GCC_WARN_UNUSED_VARIABLE = YES; 393 | IPHONEOS_DEPLOYMENT_TARGET = 12.2; 394 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 395 | MTL_FAST_MATH = YES; 396 | ONLY_ACTIVE_ARCH = YES; 397 | SDKROOT = iphoneos; 398 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 399 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 400 | VERSIONING_SYSTEM = "apple-generic"; 401 | VERSION_INFO_PREFIX = ""; 402 | }; 403 | name = Debug; 404 | }; 405 | 4922F97822AAE53700967BB5 /* Release */ = { 406 | isa = XCBuildConfiguration; 407 | buildSettings = { 408 | ALWAYS_SEARCH_USER_PATHS = NO; 409 | CLANG_ANALYZER_NONNULL = YES; 410 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 411 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 412 | CLANG_CXX_LIBRARY = "libc++"; 413 | CLANG_ENABLE_MODULES = YES; 414 | CLANG_ENABLE_OBJC_ARC = YES; 415 | CLANG_ENABLE_OBJC_WEAK = YES; 416 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 417 | CLANG_WARN_BOOL_CONVERSION = YES; 418 | CLANG_WARN_COMMA = YES; 419 | CLANG_WARN_CONSTANT_CONVERSION = YES; 420 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 421 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 422 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 423 | CLANG_WARN_EMPTY_BODY = YES; 424 | CLANG_WARN_ENUM_CONVERSION = YES; 425 | CLANG_WARN_INFINITE_RECURSION = YES; 426 | CLANG_WARN_INT_CONVERSION = YES; 427 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 428 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 429 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 430 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 431 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 432 | CLANG_WARN_STRICT_PROTOTYPES = YES; 433 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 434 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 435 | CLANG_WARN_UNREACHABLE_CODE = YES; 436 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 437 | CODE_SIGN_IDENTITY = "iPhone Developer"; 438 | COPY_PHASE_STRIP = NO; 439 | CURRENT_PROJECT_VERSION = 1; 440 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 441 | ENABLE_NS_ASSERTIONS = NO; 442 | ENABLE_STRICT_OBJC_MSGSEND = YES; 443 | GCC_C_LANGUAGE_STANDARD = gnu11; 444 | GCC_NO_COMMON_BLOCKS = YES; 445 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 446 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 447 | GCC_WARN_UNDECLARED_SELECTOR = YES; 448 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 449 | GCC_WARN_UNUSED_FUNCTION = YES; 450 | GCC_WARN_UNUSED_VARIABLE = YES; 451 | IPHONEOS_DEPLOYMENT_TARGET = 12.2; 452 | MTL_ENABLE_DEBUG_INFO = NO; 453 | MTL_FAST_MATH = YES; 454 | SDKROOT = iphoneos; 455 | SWIFT_COMPILATION_MODE = wholemodule; 456 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 457 | VALIDATE_PRODUCT = YES; 458 | VERSIONING_SYSTEM = "apple-generic"; 459 | VERSION_INFO_PREFIX = ""; 460 | }; 461 | name = Release; 462 | }; 463 | 4922F97A22AAE53700967BB5 /* Debug */ = { 464 | isa = XCBuildConfiguration; 465 | buildSettings = { 466 | CODE_SIGN_IDENTITY = ""; 467 | CODE_SIGN_STYLE = Manual; 468 | DEFINES_MODULE = YES; 469 | DYLIB_COMPATIBILITY_VERSION = 1; 470 | DYLIB_CURRENT_VERSION = 1; 471 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 472 | INFOPLIST_FILE = CollapseTableView/Info.plist; 473 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 474 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 475 | LD_RUNPATH_SEARCH_PATHS = ( 476 | "$(inherited)", 477 | "@executable_path/Frameworks", 478 | "@loader_path/Frameworks", 479 | ); 480 | MARKETING_VERSION = 1.0.3; 481 | PRODUCT_BUNDLE_IDENTIFIER = sk.CollapseTableView; 482 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 483 | PROVISIONING_PROFILE_SPECIFIER = ""; 484 | SKIP_INSTALL = YES; 485 | SUPPORTS_MACCATALYST = YES; 486 | SWIFT_VERSION = 5.0; 487 | TARGETED_DEVICE_FAMILY = "1,2"; 488 | }; 489 | name = Debug; 490 | }; 491 | 4922F97B22AAE53700967BB5 /* Release */ = { 492 | isa = XCBuildConfiguration; 493 | buildSettings = { 494 | CODE_SIGN_IDENTITY = ""; 495 | CODE_SIGN_STYLE = Manual; 496 | DEFINES_MODULE = YES; 497 | DYLIB_COMPATIBILITY_VERSION = 1; 498 | DYLIB_CURRENT_VERSION = 1; 499 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 500 | INFOPLIST_FILE = CollapseTableView/Info.plist; 501 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 502 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 503 | LD_RUNPATH_SEARCH_PATHS = ( 504 | "$(inherited)", 505 | "@executable_path/Frameworks", 506 | "@loader_path/Frameworks", 507 | ); 508 | MARKETING_VERSION = 1.0.3; 509 | PRODUCT_BUNDLE_IDENTIFIER = sk.CollapseTableView; 510 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 511 | PROVISIONING_PROFILE_SPECIFIER = ""; 512 | SKIP_INSTALL = YES; 513 | SUPPORTS_MACCATALYST = YES; 514 | SWIFT_VERSION = 5.0; 515 | TARGETED_DEVICE_FAMILY = "1,2"; 516 | }; 517 | name = Release; 518 | }; 519 | /* End XCBuildConfiguration section */ 520 | 521 | /* Begin XCConfigurationList section */ 522 | 4919EFDC22AC25D500CD5A74 /* Build configuration list for PBXNativeTarget "CollapseTableViewDemo" */ = { 523 | isa = XCConfigurationList; 524 | buildConfigurations = ( 525 | 4919EFDA22AC25D500CD5A74 /* Debug */, 526 | 4919EFDB22AC25D500CD5A74 /* Release */, 527 | ); 528 | defaultConfigurationIsVisible = 0; 529 | defaultConfigurationName = Release; 530 | }; 531 | 4922F96B22AAE53700967BB5 /* Build configuration list for PBXProject "CollapseTableView" */ = { 532 | isa = XCConfigurationList; 533 | buildConfigurations = ( 534 | 4922F97722AAE53700967BB5 /* Debug */, 535 | 4922F97822AAE53700967BB5 /* Release */, 536 | ); 537 | defaultConfigurationIsVisible = 0; 538 | defaultConfigurationName = Release; 539 | }; 540 | 4922F97922AAE53700967BB5 /* Build configuration list for PBXNativeTarget "CollapseTableView" */ = { 541 | isa = XCConfigurationList; 542 | buildConfigurations = ( 543 | 4922F97A22AAE53700967BB5 /* Debug */, 544 | 4922F97B22AAE53700967BB5 /* Release */, 545 | ); 546 | defaultConfigurationIsVisible = 0; 547 | defaultConfigurationName = Release; 548 | }; 549 | /* End XCConfigurationList section */ 550 | }; 551 | rootObject = 4922F96822AAE53700967BB5 /* Project object */; 552 | } 553 | -------------------------------------------------------------------------------- /CollapseTableView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CollapseTableView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /CollapseTableView.xcodeproj/project.xcworkspace/xcuserdata/serhii_kharauzov.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kharauzov/CollapseTableView/95126e81081ffb951050c371a1ad7dbb77fe4b53/CollapseTableView.xcodeproj/project.xcworkspace/xcuserdata/serhii_kharauzov.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /CollapseTableView.xcodeproj/xcuserdata/serhii_kharauzov.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /CollapseTableView.xcodeproj/xcuserdata/serhii_kharauzov.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CollapseTableView.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | CollapseTableViewDemo.xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 1 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /CollapseTableView/CollapseTableView.h: -------------------------------------------------------------------------------- 1 | // 2 | // CollapseTableView.h 3 | // CollapseTableView 4 | // 5 | // Created by Serhii Kharauzov on 6/7/19. 6 | // Copyright © 2019 Serhii Kharauzov. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for CollapseTableView. 12 | FOUNDATION_EXPORT double CollapseTableViewVersionNumber; 13 | 14 | //! Project version string for CollapseTableView. 15 | FOUNDATION_EXPORT const unsigned char CollapseTableViewVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /CollapseTableView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | $(MARKETING_VERSION) 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | 22 | 23 | -------------------------------------------------------------------------------- /CollapseTableView/Source/CollapseSectionHeader.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CollapseSectionHeader.swift 3 | // CollapseTableView 4 | // 5 | // Created by Serhii Kharauzov on 6/7/19. 6 | // Copyright © 2019 Serhii Kharauzov. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | public protocol CollapseSectionHeader { 13 | /// Shows open/close state of section. 14 | var indicatorImageView: UIImageView { get } 15 | /// Default value is 0.25. 16 | var imageAnimationDuration: TimeInterval { get } 17 | 18 | /// Default implementation: rotates `indicatorImageView` in 19 | /// appropriate direction. 20 | func updateViewForOpenState(animated: Bool) 21 | /// Default implementation: rotates `indicatorImageView` in 22 | /// appropriate direction. 23 | func updateViewForCloseState(animated: Bool) 24 | } 25 | 26 | // MARK: Default implementation of methods and properties. 27 | 28 | /// One can override them in own custom view, adopting `CollapseSectionHeader` protocol. 29 | 30 | extension CollapseSectionHeader { 31 | public var imageAnimationDuration: TimeInterval { 32 | return 0.25 33 | } 34 | 35 | public func updateViewForOpenState(animated: Bool) { 36 | let duration = animated ? imageAnimationDuration : 0 37 | UIView.animate(withDuration: duration) { 38 | self.indicatorImageView.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi)) 39 | } 40 | } 41 | 42 | public func updateViewForCloseState(animated: Bool) { 43 | let duration = animated ? imageAnimationDuration : 0 44 | UIView.animate(withDuration: duration) { 45 | self.indicatorImageView.transform = CGAffineTransform(rotationAngle: CGFloat(2 * Double.pi)) 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /CollapseTableView/Source/CollapseTableView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CollapseTableView.swift 3 | // CollapseTableView 4 | // 5 | // Created by Serhii Kharauzov on 6/6/19. 6 | // Copyright © 2019 Serhii Kharauzov. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | open class CollapseTableView: UITableView { 12 | /// 13 | private weak var collapseDataSource: UITableViewDataSource? 14 | /// 15 | private weak var collapseDelegate: UITableViewDelegate? 16 | /// Represents opened/closed states of tableView's sections. 17 | private(set) var sectionStates = [Bool]() 18 | /// Determines, if section's headerView can be clickable. 19 | /// `True` by default. 20 | public var shouldHandleHeadersTap = true 21 | /// Completion, invoked on section tap. 22 | public var didTapSectionHeaderView: ((_ sectionIndex: Int, _ isOpen: Bool) -> Void)? 23 | 24 | // MARK: System 25 | 26 | override open var dataSource: UITableViewDataSource? { 27 | set { 28 | self.collapseDataSource = newValue 29 | super.dataSource = self.collapseDataSource != nil ? self : nil 30 | } get { 31 | return super.dataSource 32 | } 33 | } 34 | 35 | override open var delegate: UITableViewDelegate? { 36 | set { 37 | self.collapseDelegate = newValue 38 | super.delegate = self.collapseDelegate != nil ? self : nil 39 | } get { 40 | return super.delegate 41 | } 42 | } 43 | 44 | override open func forwardingTarget(for aSelector: Selector!) -> Any? { 45 | if collapseDataSource?.responds(to: aSelector) ?? false { 46 | return collapseDataSource 47 | } 48 | if collapseDelegate?.responds(to: aSelector) ?? false { 49 | return collapseDelegate 50 | } 51 | return nil 52 | } 53 | 54 | override open func responds(to aSelector: Selector!) -> Bool { 55 | if sel_isEqual(aSelector, #selector(tableView(_:viewForHeaderInSection:))) { 56 | return collapseDelegate?.responds(to: aSelector) ?? false 57 | } 58 | return super.responds(to: aSelector) || collapseDataSource?.responds(to: aSelector) ?? false || collapseDelegate?.responds(to: aSelector) ?? false 59 | } 60 | 61 | // MARK: Public methods 62 | 63 | public func toggleSection(_ sectionIndex: Int, animated: Bool) { 64 | if sectionIndex >= sectionStates.count { 65 | return 66 | } 67 | let sectionIsOpen = sectionStates[sectionIndex] 68 | if sectionIsOpen { 69 | closeSection(sectionIndex, animated: animated) 70 | didTapSectionHeaderView?(sectionIndex, false) 71 | } else { 72 | openSection(sectionIndex, animated: animated) 73 | didTapSectionHeaderView?(sectionIndex, true) 74 | } 75 | } 76 | 77 | public func openSection(_ sectionIndex: Int, animated: Bool) { 78 | if sectionIndex >= sectionStates.count || sectionStates[sectionIndex] { 79 | return 80 | } 81 | setSectionAtIndex(sectionIndex, open: true) 82 | if let headerView = headerView(forSection: sectionIndex) as? CollapseSectionHeader { 83 | headerView.updateViewForOpenState(animated: true) 84 | } 85 | if animated { 86 | if let indexPathsToInsert = indexPathsForRowsInSectionAtIndex(sectionIndex) { 87 | insertRows(at: indexPathsToInsert, with: .top) 88 | } 89 | } else { 90 | reloadData() 91 | } 92 | } 93 | 94 | public func closeSection(_ sectionIndex: Int, animated: Bool) { 95 | if sectionIndex >= sectionStates.count { 96 | return 97 | } 98 | setSectionAtIndex(sectionIndex, open: false) 99 | if let headerView = headerView(forSection: sectionIndex) as? CollapseSectionHeader { 100 | headerView.updateViewForCloseState(animated: true) 101 | } 102 | if animated { 103 | if let indexPathsToDelete = indexPathsForRowsInSectionAtIndex(sectionIndex) { 104 | deleteRows(at: indexPathsToDelete, with: .top) 105 | } 106 | } else { 107 | reloadData() 108 | } 109 | } 110 | 111 | public func isOpenSection(_ sectionIndex: Int) -> Bool { 112 | if sectionIndex >= sectionStates.count { 113 | return false 114 | } 115 | return sectionStates[sectionIndex] 116 | } 117 | 118 | // MARK: Private methods 119 | 120 | private func setSectionAtIndex(_ sectionIndex: Int, open: Bool) { 121 | if sectionIndex >= sectionStates.count { 122 | return 123 | } 124 | sectionStates[sectionIndex] = open 125 | } 126 | 127 | private func indexPathsForRowsInSectionAtIndex(_ sectionIndex: Int) -> [IndexPath]? { 128 | guard let collapseDataSource = collapseDataSource else { 129 | return nil 130 | } 131 | if sectionIndex >= sectionStates.count { 132 | return nil 133 | } 134 | let numberOfRows = collapseDataSource.tableView(self, numberOfRowsInSection: sectionIndex) 135 | var array = [IndexPath]() 136 | for index in 0 ..< numberOfRows { 137 | array.append(IndexPath(row: index, section: sectionIndex)) 138 | } 139 | return array 140 | } 141 | 142 | @objc private func handleTapGesture(_ sender: UITapGestureRecognizer) { 143 | guard let view = sender.view, view.tag >= 0 else { 144 | return 145 | } 146 | toggleSection(view.tag, animated: true) 147 | } 148 | } 149 | 150 | // MARK: UITableViewDataSource 151 | 152 | extension CollapseTableView: UITableViewDataSource { 153 | public func numberOfSections(in tableView: UITableView) -> Int { 154 | let numberOfSections = collapseDataSource?.numberOfSections?(in: tableView) ?? 0 155 | while numberOfSections < sectionStates.count { 156 | sectionStates.removeAll() 157 | } 158 | while numberOfSections > sectionStates.count { 159 | sectionStates.append(false) 160 | } 161 | return numberOfSections 162 | } 163 | 164 | public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 165 | if sectionStates[section] { 166 | return collapseDataSource?.tableView(tableView, numberOfRowsInSection: section) ?? 0 167 | } 168 | return 0 169 | } 170 | 171 | public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 172 | return collapseDataSource?.tableView(tableView, cellForRowAt: indexPath) ?? UITableViewCell() 173 | } 174 | } 175 | 176 | // MARK: UITableViewDelegate 177 | 178 | extension CollapseTableView: UITableViewDelegate { 179 | public func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 180 | guard let view = collapseDelegate?.tableView?(tableView, viewForHeaderInSection: section) else { 181 | return nil 182 | } 183 | if shouldHandleHeadersTap { 184 | let gestures = view.gestureRecognizers ?? [] 185 | var tapGestureFound = false 186 | for gesture in gestures { 187 | if gesture.isKind(of: UITapGestureRecognizer.self) { 188 | tapGestureFound = true 189 | break 190 | } 191 | } 192 | if !tapGestureFound { 193 | view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(_:)))) 194 | } 195 | } 196 | view.tag = section 197 | if let collapseSectionHeader = view as? CollapseSectionHeader { 198 | if isOpenSection(section) { 199 | collapseSectionHeader.updateViewForOpenState(animated: false) 200 | } else { 201 | collapseSectionHeader.updateViewForCloseState(animated: false) 202 | } 203 | } 204 | return view 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /CollapseTableViewDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CollapseTableViewDemo 4 | // 5 | // Created by Serhii Kharauzov on 6/8/19. 6 | // Copyright © 2019 Serhii Kharauzov. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /CollapseTableViewDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /CollapseTableViewDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /CollapseTableViewDemo/Assets.xcassets/arrow_down.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "arrow_down.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | }, 12 | "properties" : { 13 | "preserves-vector-representation" : true 14 | } 15 | } -------------------------------------------------------------------------------- /CollapseTableViewDemo/Assets.xcassets/arrow_down.imageset/arrow_down.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kharauzov/CollapseTableView/95126e81081ffb951050c371a1ad7dbb77fe4b53/CollapseTableViewDemo/Assets.xcassets/arrow_down.imageset/arrow_down.pdf -------------------------------------------------------------------------------- /CollapseTableViewDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /CollapseTableViewDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /CollapseTableViewDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.1 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /CollapseTableViewDemo/ReusableView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ReusableView.swift 3 | // 4 | // 5 | // Created by Serhii Kharauzov on 1/9/18. 6 | // Copyright © 2018 Serhii Kharauzov. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | /// Object, that adopts this protocol, will use identifier that matches name of its class. 13 | protocol ReusableView: class {} 14 | 15 | extension ReusableView { 16 | static var reuseIdentifier: String { 17 | return String(describing: self) 18 | } 19 | } 20 | 21 | extension UIView: ReusableView {} 22 | -------------------------------------------------------------------------------- /CollapseTableViewDemo/SectionHeaderView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SectionHeaderView.swift 3 | // CollapseTableView 4 | // 5 | // Created by Serhii Kharauzov on 6/7/19. 6 | // Copyright © 2019 Serhii Kharauzov. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CollapseTableView 11 | 12 | class SectionHeaderView: UITableViewHeaderFooterView, CollapseSectionHeader { 13 | 14 | @IBOutlet weak var imageView: UIImageView! 15 | 16 | var indicatorImageView: UIImageView { 17 | return imageView 18 | } 19 | 20 | override func awakeFromNib() { 21 | super.awakeFromNib() 22 | imageView.image = #imageLiteral(resourceName: "arrow_down").withRenderingMode(.alwaysTemplate) 23 | imageView.tintColor = .white 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /CollapseTableViewDemo/SectionHeaderView.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /CollapseTableViewDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CollapseTableView 4 | // 5 | // Created by Serhii Kharauzov on 6/6/19. 6 | // Copyright © 2019 Serhii Kharauzov. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CollapseTableView 11 | 12 | class ViewController: UIViewController { 13 | 14 | @IBOutlet weak var tableView: CollapseTableView! 15 | 16 | override func viewDidLoad() { 17 | super.viewDidLoad() 18 | setupTableView() 19 | tableView.didTapSectionHeaderView = { (sectionIndex, isOpen) in 20 | debugPrint("sectionIndex \(sectionIndex), isOpen \(isOpen)") 21 | } 22 | reloadTableView { [unowned self] in 23 | self.tableView.openSection(0, animated: true) 24 | } 25 | } 26 | 27 | func setupTableView() { 28 | tableView.delegate = self 29 | tableView.dataSource = self 30 | tableView.tableFooterView = UIView(frame: .zero) 31 | tableView.register(UINib(nibName: SectionHeaderView.reuseIdentifier, bundle: nil), forHeaderFooterViewReuseIdentifier: SectionHeaderView.reuseIdentifier) 32 | } 33 | 34 | func reloadTableView(_ completion: @escaping () -> Void) { 35 | CATransaction.begin() 36 | CATransaction.setCompletionBlock({ 37 | completion() 38 | }) 39 | tableView.reloadData() 40 | CATransaction.commit() 41 | } 42 | } 43 | 44 | extension ViewController: UITableViewDataSource, UITableViewDelegate { 45 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 46 | return 4 47 | } 48 | 49 | func numberOfSections(in tableView: UITableView) -> Int { 50 | return 4 51 | } 52 | 53 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 54 | let cell = tableView.dequeueReusableCell(withIdentifier: "customCell", for: indexPath) 55 | cell.textLabel?.text = "Text for cell #\(indexPath.row + 1)" 56 | return cell 57 | } 58 | 59 | func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 60 | guard let view = tableView.dequeueReusableHeaderFooterView(withIdentifier: SectionHeaderView.reuseIdentifier) else { 61 | let view = Bundle.main.loadNibNamed(SectionHeaderView.reuseIdentifier, owner: self, options: nil)?.first as? SectionHeaderView 62 | return view 63 | } 64 | return view 65 | } 66 | 67 | func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { 68 | return 1 69 | } 70 | 71 | func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 72 | return 44 73 | } 74 | 75 | func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 76 | return 44 77 | } 78 | } 79 | 80 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Serhii Kharauzov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Swift](https://img.shields.io/badge/Swift-5.0-orange.svg) 2 | ![Platform](https://img.shields.io/badge/platform-iOS-lightgrey.svg) 3 | [![License](https://img.shields.io/badge/license-mit-blue.svg)](https://doge.mit-license.org) 4 | 5 | ## Overview 6 | This is a Swift version of [STCollapseTableView](https://github.com/iSofTom/STCollapseTableView) that was written in Objective-C. 7 | 8 | CollapseTableView enables you to make expandable UITableView's sections with just a few lines of code. 9 | 10 | ## Presentation 11 |

12 | 13 |

14 | 15 | ## Installation 16 | 17 | ### CocoaPods 18 | 19 | ```ruby 20 | pod 'CollapseTableView' 21 | ``` 22 | 23 | ### Manually 24 | 25 | Just copy **Source** folder to your Xcode project. 26 | 27 | ## How To 28 | 29 | After adding the framework to your project, you need to import the module 30 | ```swift 31 | import CollapseTableView 32 | ``` 33 | 34 | Then you need to subclass your *UITableView* with *CollapseTableView* and set delegate/datasource as you always do. 35 | By default, tableView sections are clickable and expandable. 36 | 37 | If you want to disable clickability of sections, there is a special property for this: 38 | 39 | ```swift 40 | public var shouldHandleHeadersTap: Bool 41 | ``` 42 | 43 | So after you implement standard tableView's dataSource/delegate methods for sections, you will be able to open or close the sections with your cells by clicking them. 44 | 45 | There're extra tableView methods for work with sections: 46 | 47 | ```swift 48 | public func toggleSection(_ sectionIndex: Int, animated: Bool) 49 | public func openSection(_ sectionIndex: Int, animated: Bool) 50 | public func closeSection(_ sectionIndex: Int, animated: Bool) 51 | public func isOpenSection(_ sectionIndex: Int) -> Bool 52 | ``` 53 | 54 | There's a closure to observe events for opening/closing sections: 55 | ```swift 56 | tableView.didTapSectionHeaderView = { (sectionIndex, isOpen) in 57 | 58 | } 59 | ``` 60 | 61 | ## Features 62 | - [ ] Exlusive sections mode (Max 1 opened section) 63 | 64 | ## Feedback 65 | If you have any questions or suggestions, feel free to open issue just at this project. 66 | 67 | ## License 68 | CollapseTableView and all its classes are available under the MIT license. See the LICENSE file for more info. 69 | -------------------------------------------------------------------------------- /collapseTableViewDemo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kharauzov/CollapseTableView/95126e81081ffb951050c371a1ad7dbb77fe4b53/collapseTableViewDemo.gif --------------------------------------------------------------------------------