✨ Awesome expandable, collapsible tableview cell for iOS written in Swift 5

Overview

ExpandableCell

Awesome Version Carthage Compatible License: MIT Platform Swift 5.0 iOS 8.0+

Intoduction

Fully refactored YNExapnadableCell with more concise, bug free. Easiest usage of expandable & collapsible cell for iOS, written in Swift 5. You can customize expandable UITableViewCell whatever you like. ExpandableCell is made because insertRows and deleteRows is hard to use. Just inheirt ExpandableDelegate

demo

Usage

Basic

import ExpandableCell

Make ExpandableTableView in Storyboard or in code

@IBOutlet var tableView: ExpandableTableView!

Inherit ExpandableDelegate

class ViewController: UIViewController, ExpandableDelegate 

Set delegate

tableView.expandableDelegate = self

Set required ExpandableDelegate method.

Key two methods

Required ExpandableDelegate Explanation
func expandableTableView(_ expandableTableView: ExpandableTableView, expandedCellsForRowAt indexPath: IndexPath) -> [UITableViewCell]? Key method to get expandable cells
func expandableTableView(_ expandableTableView: ExpandableTableView, heightsForExpandedRowAt indexPath: IndexPath) -> [CGFloat]? Key method to get expandable cells's height
Required UITableViewDelegate, UITableViewDataSource Explanation
func expandableTableView(_ expandableTableView: ExpandableTableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell -
func expandableTableView(_ expandableTableView: ExpandableTableView, numberOfRowsInSection section: Int) -> Int -
func expandableTableView(_ expandableTableView: ExpandableTableView, heightForRowAt indexPath: IndexPath) -> CGFloat -

Advanced

ExpandableTableView property

Property Type Explanation
animation UITableViewRowAnimation Animation when open and close
expansionStyle ExpandableTableView.ExpansionStyle Select expansion type:
single - one row at a time;
singlePerSection - one row at a time, per section;
multi - any number of rows at a time
autoRemoveSelection Bool autoRemoveSelection true means the cell will flicker selected, and autoRemoveSelection false means the default selection behaviour of the tableview will apply (single or multi selection)

ExpandableTableView methods

Method Explanation
openAll Open all that you set in func expandableTableView(_ expandableTableView: ExpandableTableView, expandedCellsForRowAt indexPath: IndexPath) -> [UITableViewCell]?
closeAll Close all that you set in func expandableTableView(_ expandableTableView: ExpandableTableView, expandedCellsForRowAt indexPath: IndexPath) -> [UITableViewCell]?
reloadData TableView reload data. Expanded cells will be work also
open(at indexPath: IndexPath) Open specific indexPath

Optional delegates

Optional ExpandableDelegate Explanation
func expandableTableView(_ expandableTableView: ExpandableTableView, didSelectExpandedRowAt indexPath: IndexPath) Get indexpath in expanded row
func expandableTableView(_ expandableTableView: ExpandableTableView, expandedCell: UITableViewCell, didSelectExpandedRowAt indexPath: IndexPath) Get expandedCell and indexPath
Optional UITableViewDelegate, UITableViewDataSource Explanation
func expandableTableView(_ expandableTableView: ExpandableTableView, didSelectRowAt indexPath: IndexPath) -
func expandableTableView(_ expandableTableView: ExpandableTableView, titleForHeaderInSection section: Int) -> String? -
func expandableTableView(_ expandableTableView: ExpandableTableView, heightForHeaderInSection section: Int) -> CGFloat -
func expandableTableView(_ expandableTableView: ExpandableTableView, viewForHeaderInSection section: Int) -> UIView? -
func numberOfSections(in expandableTableView: ExpandableTableView) -> Int -
func expandableTableView(_ expandableTableView: ExpandableTableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) -
func expandableTableView(_ expandableTableView: ExpandableTableView, willDisplayHeaderView view: UIView, forSection section: Int) -
func expandableTableView(_ expandableTableView: ExpandableTableView, willDisplayFooterView view: UIView, forSection section: Int) -

For arrow effect

Inherit ExpandableCell when you need arrow effect or change arrow image

open class ExpandableCell: UITableViewCell {
    open var arrowImageView: UIImageView!
}

For highlight animation

Inherit ExpandableCell when you need disable or enable highlight animation

open class ExpandableCell: UITableViewCell {
    open var highlightAnimation = HighlightAnimation.animated
}

Adding right margin to arrow icon

Inherit ExpandableCell when you need right margin ( Default margin is 16 )

open class ExpandableCell: UITableViewCell {
    open var rightMargin: CGFloat = 16
}

Set tableview insert animation

tableView.animation = .automatic

Make protocols in ExpandableDelegate if you need or make pull request to me :)

ExpandableCell methods

ExpandableCell methods Explanation
isExpanded() Check if cell is expanded or not
isInitiallyExpanded() Make cell be open when the tableView content first appears in the view
isSelectable() Make cell be selectable or not, regardless of tableView selectionStyle

Requirements

ExpandableCell written in Swift 5.0. Compatible with iOS 8.0+

Installation

Cocoapods

ExpandableCell is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ExpandableCell'

Carthage

github "younatics/ExpandableCell"

References

Please tell me or make pull request if you use this library in your application :)

Author

younatics Twitter

License

ExpandableCell is available under the MIT license. See the LICENSE file for more info.

Comments
  • In expanded cells, 'SELECTED' mode 'ON' for multiple cells

    In expanded cells, 'SELECTED' mode 'ON' for multiple cells

    If I select a expanded cell, it's perfectly alright. But when I go for another selection, both selected cells are being highlighted. So more than one item selection makes this issue. Please let me know if it already has a solution or any way around?

    opened by mustafiz012 19
  • Crash when opening cells in different sections

    Crash when opening cells in different sections

    Hi. I get a crash when trying to open expandable cells in different sections. Index out of range. Works fine when opening multiple expandable cells in the same section just not in two (or more I'm assuming) different sections. I need this to work without closing the already opened cell. Not sure how to fix this.

    Simplest ViewController code below:

    import UIKit
    import ExpandableCell
    
    
    
    class MyTableViewController: UIViewController {
    
        
        @IBOutlet var tableView: ExpandableTableView!
        
        
        var cell: UITableViewCell {
            return tableView.dequeueReusableCell(withIdentifier: ExpandedButtonCell.ID)!
        }
        
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
            tableView.expandableDelegate = self
            //tableView.openAll()
            tableView.register(UINib(nibName: "NormalExpandableCell", bundle: nil), forCellReuseIdentifier: NormalExpandableCell.ID)
            tableView.register(UINib(nibName: "ExpandedButtonCell", bundle: nil), forCellReuseIdentifier: ExpandedButtonCell.ID)
        }
    }
    
    
    extension MyTableViewController: ExpandableDelegate {
        
        
        // Number of sections
        func numberOfSections(in expandableTableView: ExpandableTableView) -> Int {
            return 2
        }
        
        // Number of rows in section
        func expandableTableView(_ expandableTableView: ExpandableTableView, numberOfRowsInSection section: Int) -> Int {
            return 2
        }
        
        // Cells for row at (returns the main top level cells)
        func expandableTableView(_ expandableTableView: ExpandableTableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            guard let cell = expandableTableView.dequeueReusableCell(withIdentifier: NormalExpandableCell.ID) else { return UITableViewCell() }
            return cell
        }
        
        // Expanded Cells for row
        func expandableTableView(_ expandableTableView: ExpandableTableView, expandedCellsForRowAt indexPath: IndexPath) -> [UITableViewCell]? {
            return [cell, cell, cell]
        }
        
        // height for row
        func expandableTableView(_ expandableTableView: ExpandableTableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
            return 100
        }
        
        
        // heights for expanded row at
        func expandableTableView(_ expandableTableView: ExpandableTableView, heightsForExpandedRowAt indexPath: IndexPath) -> [CGFloat]? {
            return [44, 44, 44]
        }
    
    }
    
    
    // EXPANDABLE CELLS HERE
    class NormalExpandableCell: ExpandableCell {
        static let ID = "NormalExpandableCell"
    }
    
    
    class ExpandedButtonCell: UITableViewCell {
        static let ID = "ExpandedButtonCell"
    
    }
    
    opened by seanonthenet 14
  • issue with tabbar controller

    issue with tabbar controller

    I have a tabbar controller. ViewController A with expandable table view inside View Controller B without. Just empty one

    I open A. opened B then Open A

    expandable table view is not working and crashes

    I reproduced this issue with demo app. Just embed in tabbarcontroller instead of navigation controller. please help

    opened by DKalachniuk 5
  • When I expand the cell then it crashes if one cell is already expended in the following method.

    When I expand the cell then it crashes if one cell is already expended in the following method.

    Some time it crashes because filteredExpandedDatas having no object at that time.

    func indexPathsWhere(indexPath: IndexPath) -> [IndexPath] { let filteredExpandedDatas = expandableDatas.filter({ (expandedData: ExpandableData) -> Bool in return (expandedData.indexPath == indexPath) }) if filteredExpandedDatas.count > 1 { fatalError("Something Wrong") } return filteredExpandedDatas[0].expandedIndexPaths }

    opened by Pinturaj 5
  • Adds new Expansion style

    Adds new Expansion style

    • Adds new ExpansionStyle: singlePerSection;
    • Adapts existing code to handle new style.

    Notes:

    1. This PR is based on PR #53 (where the initial idea for this new case came from);
    2. Demo (ExpandableCellDemo) wasn't updated with a new button to test this new expansion style behaviour to avoid "overcrowding" the navigation bar with buttons. TL;DR: it can be easily tested by simply replacing the style (ExpansionStyle.single) currently set in method ViewController.expandSingleButtonClicked(_:) with ExpansionStyle.singlePerSection.
    opened by robertogvieira 4
  • Error:  Cell become white when scroll Table View

    Error: Cell become white when scroll Table View

    When i click expandable cell and scroll table view or expandable and collap cell, Cell become white . my iphone (ios6s version: 11.4.1) bugCell.zip bugcellwhite bugwhitecell

    opened by huynh-dat-mulodo 3
  • Make reloadExpandableExpandedCells refresh expanded section without close/open

    Make reloadExpandableExpandedCells refresh expanded section without close/open

    I wanted to dynamically update an expanded section, but the current implementation looks really odd to users. I think it is because it is actually removing all visible rows, updating, and then adding rows and updating again.

    I just extracted out some of the open/close methods that I would like to use into their own functions, and then call those. I'm open to different names for the extracted functions if you don't like them.

    opened by devguy22 3
  • Need to expand only One cell at a time.

    Need to expand only One cell at a time.

    Is there a way that i could should only one expended cell in table. Ex: Let say User selected Cell A it's expended but when User select Cell B, cell A should close and B open automatically.

    opened by asrivastava15 3
  • tableviewcell not using set constraints

    tableviewcell not using set constraints

    Hi @younatics ,

    This library is cool, I want to use it in one of my applications. But I have issue in rendering the tableviewcell. I manage to use a custom tableviewcell but the problem is the constraints I set in the cell is I think overwritten.

    Please see screenshot below.

    Storyboard cell with costraints.

    screen shot 2017-08-12 at 11 23 59 am

    Actual result.

    screen shot 2017-08-12 at 11 24 11 am

    Hoping for your response.

    Thank you.

    opened by rjjohnpatrickcruz 3
  • how to collapseAll

    how to collapseAll

    Hi @younatics thanks for the neat refactored code!

    can you add in the previously requested collapse All and open single expandable cell please?

    Cheers

    Des

    enhancement 
    opened by kohdesmond 3
  • Compiler error

    Compiler error

    Started getting this error after pod install:

    Multiple commands produce '/Users/fedor/Library/Developer/Xcode/DerivedData/...-bgbdsrxqedljvpcbxvkmpclubaes/Build/Products/Debug-iphoneos/.../Assets.car':

    1. Target '...' (project '...') has compile command with input '/Users/fedor/.../.../.../Assets.xcassets'
    2. That command depends on command in Target '...' (project '...'): script phase “[CP] Copy Pods Resources”

    There are also two warnings:

    1. duplicate output file '/Users/fedor/Library/Developer/Xcode/DerivedData/...-bgbdsrxqedljvpcbxvkmpclubaes/Build/Products/Debug-iphoneos/.../Assets.car' on task: PhaseScriptExecution [CP] Copy Pods Resources /Users/fedor/Library/Developer/Xcode/DerivedData/...-bgbdsrxqedljvpcbxvkmpclubaes/Build/Intermediates.noindex/.../Debug-iphoneos/.../Script-626E2A68364D360141E2BEDF.sh

    2. The app icon set name "AppIcon" is used by multiple app icon sets.

    The second one is related to the GoogleMaps pod.

    Pod version: 1.3.0. Swift version: 5.1. Xcode version: 11.3.1.

    opened by fedorpashin 2
  • Reload not working as intended only in iOS15

    Reload not working as intended only in iOS15

    When I call reloadData in the expanded cell, the order of row is scrambled and not sorted in order.

    It only happens when compiled in Xcode 13 and run in iOS15. When it's compiled in Xcode 13 and run in iOS14, it has no problem. Also, when it's compiled in Xcode 12, it runs fine in iOS15 and 14.

    Could you please fix this? Thank you.

    opened by cheehoonha-lifeoverflow 1
  • How to get IndexPath of parent list when one or more cells are expanded.

    How to get IndexPath of parent list when one or more cells are expanded.

    Is there a way to get the Indexpath of parent list. Lets

    Parent { index 0 : [child1, child2, child3] index 1 : [child 1, child 2] index 2 : null }

    How I can get the indexpath of normal cell when some of cells are expanded. In this case if index 0 is expanded and i click on normal cell then i will get indexpath (0+3+2) = 5. where as i want 2. Any way to achieve this.

    opened by aqsa-arshad08 0
  • App Crashing on expandableTableView(_:expandedCellsForRowAt:)

    App Crashing on expandableTableView(_:expandedCellsForRowAt:)

    Firebase report a non recurrent crash. It appears randomly.

    This is the crashlytics report:

    Fatal Exception: NSRangeException *** -[__NSArrayM objectAtIndexedSubscript:]: index 18446744073709551615 beyond bounds [0 .. 9] Controller.expandableTableView(_:expandedCellsForRowAt:)

    Fatal Exception: NSRangeException 0 CoreFoundation 0x18ab5986c __exceptionPreprocess 1 libobjc.A.dylib 0x19fb72c50 objc_exception_throw 2 CoreFoundation 0x18abc9e1c -[__NSCFString characterAtIndex:].cold.1 3 CoreFoundation 0x18aa47e8c -[__NSDictionaryI objectForKeyedSubscript:] 4 Souffleur de Rêves 0x102a428e4 AudioListController.expandableTableView(:expandedCellsForRowAt:) + 1218 (AudioListController.swift:1218) 5 ExpandableCell 0x103197a20 ExpandableTableView.open(indexPath:delegate:) + 111 (ExpandableTableView.swift:111) 6 ExpandableCell 0x103197280 ExpandableTableView.handleRowExpansion(at:) + 91 (ExpandableTableView.swift:91) 7 ExpandableCell 0x103196f00 ExpandableTableView.tableView(:didSelectRowAt:) + 65 (ExpandableTableView.swift:65) 8 ExpandableCell 0x103197358 @objc ExpandableTableView.tableView(_:didSelectRowAt:) () 9 UIKitCore 0x18d721830 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:isCellMultiSelect:] 10 UIKitCore 0x18d7213d8 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] 11 UIKitCore 0x18d721b98 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] 12 UIKitCore 0x18d9f7544 -[_UIAfterCACommitBlock run] 13 UIKitCore 0x18d51f00c _runAfterCACommitDeferredBlocks 14 UIKitCore 0x18d50d9a0 _cleanUpAfterCAFlushAndRunDeferredBlocks 15 UIKitCore 0x18d541bb4 _afterCACommitHandler 16 CoreFoundation 0x18aad4358 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION 17 CoreFoundation 0x18aace5c4 __CFRunLoopDoObservers 18 CoreFoundation 0x18aaceb74 __CFRunLoopRun 19 CoreFoundation 0x18aace21c CFRunLoopRunSpecific 20 GraphicsServices 0x1a2698784 GSEventRunModal 21 UIKitCore 0x18d50eee8 -[UIApplication _run] 22 UIKitCore 0x18d51475c UIApplicationMain 23 Souffleur de Rêves 0x1029f6b74 main + 32 (UIColor+Set.swift:32) 24 libdyld.dylib 0x18a78e6b0 start

    An undefined index is applied.

    If someone can help me to solve this crash issue. Thank you

    opened by bebslab 0
  • App Crashing

    App Crashing

    tableView have more data and expand very first cell and scroll to bottom section and click on the section, app will crash. I found the issue, cImageView gets nil if cell is not visible.

    Please fix this.

    opened by ErAshu 0
  • TableView freeze after pushing new ViewController

    TableView freeze after pushing new ViewController

    Thank you for this awesome library,

    I've added ExpandableCell in jonkykong/SideMenu pod, but when I try to push a new ViewController and back to the (Side Menu) I can't click on any cell in the TableView at all, all cells freeze. I tried to reloadData and reloadSection but when I back to the menu the cells disappear. I also tried it in the demo, and there is the same issue.

    How to solve this issue?

    opened by Z1Z0 7
Releases(1.3.0)
Owner
Kyle Yi
Kyle Yi
Swift library to support collapsible sections in a table view.

CollapsibleTableSectionViewController A Swift library that helps you collapse table view sections. Features Support collapsible sections in a table vi

Su 349 Dec 18, 2022
Make your table view expandable just by implementing one method.

ExpyTableView About ExpyTableView is a re-write based on SLExpandableTableView. Takes some ideas, concepts and codes and regenerates them in Swift. Le

Okhan Okbay 359 Dec 27, 2022
📃 FoldingCell is an expanding content cell with animation made by @Ramotion

FOLDING CELL Expanding content cell with animation inspired by folding paper card material design. We specialize in the designing and coding of custom

Ramotion 10.1k Jan 2, 2023
Three Level Accordian View for IOS

ThreeLevelAccordian ThreeLevelAccordian is a three level accordian for IOS. It owes its base code to SwiftyAccordionCells. Most of the design is custo

Amrata Baghel 44 Sep 23, 2022
Savory is swift accrodion view implementation

Savory Savory is a swift accordion view implementation. Requirements Xcode 8.0 Swift 3.0 iOS 8 Installation Using CocoaPods: pod 'Savory', :git => 'ht

Nandin Borjigin 4 May 30, 2019
✨ Awesome expandable, collapsible tableview cell for iOS written in Swift 5

ExpandableCell Intoduction Fully refactored YNExapnadableCell with more concise, bug free. Easiest usage of expandable & collapsible cell for iOS, wri

Kyle Yi 728 Jan 1, 2023
App uses API to display information about City and State user using expandable table cell

Expandable Table Cell iOS App App uses API to display information about City and State user using expandable table cell Implemented Using MVVM with Cl

null 2 Nov 30, 2021
UITableView cell cache that cures scroll-lags on cell instantiating

UITableView + Cache https://github.com/Kilograpp/UITableView-Cache UITableView cell cache that cures scroll-lags on a cell instantiating. Introduction

null 73 Aug 6, 2021
a TableView have thumbnail cell only, and you can use gesture let it expands other expansionView, all diy

ZYThumbnailTableView #####可展开型预览TableView,开放接口,完全自由定制 #####An expandable preview TableView, custom-made all the modules completely with open API you c

null 950 Oct 17, 2022
API-TableView-Swift - API call with URLSession and show data to TableView with swift

API-TableView-Swift API call with URLSession and show data to TableView with swi

Aman Ullah Akhand 1 Sep 3, 2022
Swift library to support collapsible sections in a table view.

CollapsibleTableSectionViewController A Swift library that helps you collapse table view sections. Features Support collapsible sections in a table vi

Su 349 Dec 18, 2022
Menu controller with expandable item groups, custom position and appearance animation written with Swift. Similar to ActionSheet style of UIAlertController.

Easy to implement controller with expanding menu items. Design is very similar to iOS native ActionSheet presentation style of a UIAlertController. As

Anatoliy Voropay 22 Dec 27, 2022
iOS library - UIScrollView driven expandable menu.

UIScrollView driven expandable menu. Description AirBar is a library for creating cool expandable menus. Library observes UIScrollView scroll and prov

Uptech 625 Nov 8, 2022
Multiplatform (iOS, macOS) SwiftUI bottom sheet drawer. Expandable bottomsheet. Slide out bottom menu

Multiplatform (iOS, macOS) SwiftUI bottom sheet drawer Features It does not re-render the background content while manipulating with the sheet iOS and

Igor 8 Nov 18, 2022
Customizable and easy to use expandable button in Swift.

ExpandableButton Requirements iOS 9.0+ Installation CocoaPods: Add the following line to your Podfile: pod 'ExpandableButton' #for swift less than 4.

Dmytro Mishchenko 98 Dec 5, 2022
Make your table view expandable just by implementing one method.

ExpyTableView About ExpyTableView is a re-write based on SLExpandableTableView. Takes some ideas, concepts and codes and regenerates them in Swift. Le

Okhan Okbay 359 Dec 27, 2022
UITableView based component designed to display a hierarchy of expandable/foldable comments.

SwiftyComments UITableView based component designed to display a hierarchy of expandable/foldable comments. Installation Manually Just copy the .swift

Stéphane Sercu 220 Dec 22, 2022
RHPreviewCell - I envied so much Spotify iOS app this great playlist preview cell 😍

I envied so much Spotify iOS app this great playlist preview cell ??, I decided to create my own one ??. Now you can give your users ability to quick check what content is hidden under your UITableViewCell. Great think is that this Library not requires 3D Touch support from user device??.

Robert Herdzik 387 Sep 23, 2022
AtomicReferenceCell - Atomic Reference Cell (Arc) for Swift

Atomic Reference Cell This project provide two structures: Arc<T> and WeakArc<T>

cjw 0 Jan 30, 2022