Giter Club home page Giter Club logo

ynexpandablecell's Introduction

USE ExpandableCell. New version of this library.

YNExpandableCell

Awesome Version Carthage Compatible CocoaPods License: MIT Build Status Platform Swift 4.2

Updates

See CHANGELOG for details

Intoduction

Easiest usage of expandable & collapsible cell for iOS, written in Swift 4.2 You can customize expandable UITableViewCell whatever you like. YNExpandableCell is made because insertRows and deleteRows is hard to use. You can just inheirt YNTableViewDelegate and add one more method func tableView(_ tableView: YNTableView, expandCellAt indexPath) -> UITableViewCell?

demo

Requirements

YNExpandableCell written in Swift 3. Compatible with iOS 8.0+

Installation

Cocoapods

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

pod 'YNExpandableCell'

Carthage

github "younatics/YNExpandableCell"

Usage

import YNExpandableCell

Make YNTableView in Storyboard or in code

@IBOutlet var ynTableView: YNTableView!

Inherit YNTableViewDelegate

class ViewController: UIViewController, YNTableViewDelegate 

Set delegate and register cells

self.ynTableView.ynDelegate = self

let cells = ["YNExpandableCellEx","YNSliderCell","YNSegmentCell"]
self.ynTableView.registerCellsWith(nibNames: cells, and: cells)
self.ynTableView.registerCellsWith(cells: [UITableViewCell.self as AnyClass], and: ["YNNonExpandableCell"])

Use one of required method

Set expandable cell in YNTableViewDelegate method (Required)

func tableView(_ tableView: YNTableView, expandCellAt indexPath: IndexPath) -> UITableViewCell? {
    let ynSliderCell = tableView.dequeueReusableCell(withIdentifier: YNSliderCell.ID) as! YNSliderCell
    if indexPath.section == 0 && indexPath.row == 1 {
        return ynSliderCell
     }
     return nil
}

Set expandable cell with height in YNTableViewDelegate method using YNTableViewCell object (Required)

func tableView(_ tableView: YNTableView, expandCellWithHeightAt indexPath: IndexPath) -> YNTableViewCell? {
    let ynSliderCell = YNTableViewCell()
    ynSliderCell.cell = tableView.dequeueReusableCell(withIdentifier: YNSliderCell.ID) as! YNSliderCell
    ynSliderCell.height = 142

    if indexPath.section == 0 && indexPath.row == 1 {
        return ynSliderCell
    }
        return nil
}

Get didSelectRowAt in YNTableViewDelegate method (Optional)

func tableView(_ tableView: YNTableView, didSelectRowAt indexPath: IndexPath, isExpandableCell: Bool, isExpandedCell: Bool) {
    print("Selected Section: \(indexPath.section) Row: \(indexPath.row) isExpandableCell: \(isExpandableCell) isExpandedCell: \(isExpandedCell)")
}

Get didDeselectRowAt in YNTableViewDelegate method (Optional)

func tableView(_ tableView: YNTableView, didDeselectRowAt indexPath: IndexPath, isExpandableCell: Bool, isExpandedCell: Bool) {
    print("Deselected Section: \(indexPath.section) Row: \(indexPath.row) isExpandableCell: \(isExpandableCell) isExpandedCell: \(isExpandedCell)")
}

Set basic UITableViewDataSource, UITableViewDelegate and Done!

Customize

Expand & Collapse All if you want

self.ynTableView.expandAll()
self.ynTableView.collapseAll()

Inherit YNExpandableCell if you want awesome '+' '-' custom accessory type

class YNExpandableCellEx: YNExpandableCell

// Change normalCustomAccessoryType, selectedCustomAccessoryType Images

Cutomize UITableViewRowAnimation

self.ynTableView.ynTableViewRowAnimation = UITableViewRowAnimation.top

Make Extensions for more UITableViewDelegate if you need or make pull request for me :)

References

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

Author

younatics Twitter

License

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

ynexpandablecell's People

Contributors

lyuxxx avatar younatics avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ynexpandablecell's Issues

Updating values of expandable cells

Where and how would i update content of expandable cells. e.g values of sliders and segment Control in your case. the delegate method expandCellWithHeight only returns the cells with the set height and doesn't allow me to access the content of the cell. This has been troubling me and i cant find a solution. please update with your response

Getting duplicated overlapping cells

Hi,

I've been trying to figure out why I get duplicated cells using your pod.

screen shot 2017-10-27 at 3 54 05 pm

Here's the result, but those 2 rows have 2 other rows behind them:
screen shot 2017-10-27 at 3 54 29 pm

As you can see in the image above, my table ends up having 2 copies that are identical, but overlapping. The data is returning 2 rows, but the cellForRowAtIndePath gets called 4 times instead of 2.

If I take out the code that assigns the ynDelegate to self, i.e.:
// self.customTableView.ynDelegate = self, it works fine. But of course I'll lose the functionality that is in this pod.

I made sure that the UITableView in the storyboard isn't using any delegate/datasource, as these get set when assigning the ynDelegate.

Please note that I'm not using any expandable cell yet, those cells are just my own custom cells that inherit from UITableViewCell.

Any help will be greatly appreciated, thanks!

Swipe to Delete feature

I couldn't activate swipe to delete feature in this, anyway I can enable it or is it included with this plugin? If the feature's available, how to enable it?

bugs with expandCellWithHeightAt indexPath:

I think there's a bug in
func tableView(_ tableView: YNTableView, expandCellWithHeightAt indexPath: IndexPath) -> YNTableViewCell?

if i have only 2 records of cells [0,1], i expand both of them and tried to close cell 0's expanded cell,

i will get EXC_BAD_INSTRUCTION at line 172, 227 & line 279 in YNTableView.swift

if internalIndexPath == indexPath {
                self.didDeselectRowLogicAt(expandedIndexPath: expandedIndexPath, indexPath: indexPath)
                delegate.tableView(self, didDeselectRowAt: indexPath, isExpandableCell: true, isExpandedCell: false)
                return
            }

YNTableView.swift is trying to return indexPath.row 2, but my count record only have [0,1].

i tested with func tableView(_ tableView: YNTableView, expandCellAt indexPath: IndexPath) -> UITableViewCell? and it works fine. Not sure why though @younatics any comments?

Expand only one cell?

Is it possible to expand only one cell and automatically close the previuosly expanded cell (if there is one)?

expandCellWithHeightAt method not calling

While I am setting YNTableViewDelegate then tableview datasource are not getting called and tableview will blank. If I remove your delegate then tableview datasource working.

`@IBOutlet weak var tableVIewOptions: YNTableView!

override func viewDidLoad() {
    super.viewDidLoad()
    
    self.tableVIewOptions.ynDelegate = self
    self.tableVIewOptions.dataSource = self
    self.tableVIewOptions.delegate = self
    self.tableVIewOptions.ynTableViewRowAnimation = .top
    
    //hide empty rows
    tableVIewOptions.tableFooterView = UIView()
}`

2 layout bugs discovered

Hey, first of all thank you for this awesome framework im currently using it in one of my projects.

i discovered two minor yet annoying bugs in the layout of the cells, the first one is happens when expanding the one before last cell, you can see its content show up in the last cell, here's the GIF link demonstration :
whimsicaleachivorybilledwoodpecker-size_restricted

second bug happens if user multiclick a lot of the cells in a short period of time it basically messes up the layout, here's the GIF link demonstration :
glamoroustornibadanmalimbe-size_restricted

compromise between row select and expandability.

This might prove an awesome repo for me if the following is either do-able right now, or possible:

Show a set of rows, some expandable, some not BUT, expansion only occurs if the + button is tapped. Selection of the row itself should be as normal.

I will dig through the code to see if i can figure out if this is implemented.

Expansion Animation Glitches

I have a list with three expandable elements, the first element expands smoothly but the bottom two elements are juddery and seem to be skipping frames.

Is this a known issue?

overriding the heightForRowAtIndex doesn't seem to work.

In my tableview - my expandable cell needs to be larger than > 44 pixels in height.
They are 200 I need to expand to 350.

perhaps you could provide a method to check cell for initial height....

screen shot 2017-04-07 at 3 23 37 pm

// this is obvious fix - but then the expanded cells don't get correct height 
open func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    guard let delegate = self.ynDelegate else {return UITableViewAutomaticDimension}
    guard let heightForRow = delegate.tableView(self, heightForRowAt: indexPath)  else {
            print("height will be 44")
            return UITableViewAutomaticDimension
    }
    return heightForRow
}

fyi - I'm using it to expand a text section.

Multiple cells

Hi,
I want to know how i can use "n" number of rows in expanded cell. where i'll return rows in expanded cell.
Thanks.

anyway to open up the animation?

This is more of a major enhancement. But food for thought.

i wonder if you can open up the + & - animation for other images and purposes?
say expand for more details indicator
screen shot 2017-03-21 at 11 12 59

Once I tap open, it will rotate the arrow pointing up and vice versa

screen shot 2017-03-21 at 11 16 44

Add support for multiple cells in expansion

A really useful addition would be for us to be able to expand multiple cells on tap, which is really useful for screens containing selecting multiple options, checklists, etc. If it's possible, please implement this. Thanks :)

How to define a nonExpandablecell from a nib?

Hi YN,

As above.

you used an example
let nonExpandablecell = tableView.dequeueReusableCell(withIdentifier: "YNNonExpandableCell")

but i want to use a nib file as one of the nonExpandablecell. what should i do?

Cheers

Desmond

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.