younatics / expandablecell Goto Github PK
View Code? Open in Web Editor NEW✨ Awesome expandable, collapsible tableview cell for iOS written in Swift 5
License: MIT License
✨ Awesome expandable, collapsible tableview cell for iOS written in Swift 5
License: MIT License
Hi,
I have problem with application. Animation is working just fine for first 3 rows that are created on page load. For all other rows i have animation problems. Take a look at video.
Any ideas what is problem?
Hello, when the tableview becomes bigger than the view itself and there are expandable cells down not visible, their arrow gets affected depending of the visible one. So if i open 3 cells, their arrow is up. When i scroll down and see the fourth cell, its arrow will be as if it was open, but actually it is not.
How do i solve this issue ?
Thanks
` open func open() {
self.isOpen = true
self.initialExpansionAllowed = false
if highlightAnimation == .animated {
UIView.animate(withDuration: 0.1) {[weak self] in
self?.arrowImageView.layer.transform = CATransform3DMakeRotation(CGFloat(Double.pi), 1.0, 0.0, 0.0)
}
}
}
open func close() {
self.isOpen = false
if highlightAnimation == .animated {
UIView.animate(withDuration: 0.1) {[weak self] in
self?.arrowImageView.layer.transform = CATransform3DMakeRotation(CGFloat(Double.pi), 0.0, 0.0, 0.0)
}
}
}`
The doc says:
For arrow effect
Inherit ExpandableCell when you need arrow effect or change arrow imageopen class ExpandableCell: UITableViewCell {
open var arrowImageView: UIImageView!
}
But no matter what I do, I can't do anything to that arrowImageView.
Can anyone tell me how to apply change to that arrowImageView?
Whenever i tap onto a cell it won't expand anymore. The openAll() function works, but putting open(indexPath) in the didSelect method does nothing for me.
Hi,
Is it possible to use this library in a static table view?
I'm kind of stuck because for static table views, you don't have to implement the UITableViewDataSource
method but this library insists on it.
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"
}
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.
Actual result.
Hoping for your response.
Thank you.
How to have sections for grouping a set of expandable cell.
can we have sections to existing ExpandableCell segmented with two groups and allow to have expandableCell functionality?
Is it possible to add support for Swift Package Manager (SPM)? I'd like to move from Carthage to SPM...
We observed that pushing a UIViewController and returning back the expandedtableview looses cells' contents. We tried this in demo application with the same behaviour
Started getting this error after pod install:
Multiple commands produce '/Users/fedor/Library/Developer/Xcode/DerivedData/...-bgbdsrxqedljvpcbxvkmpclubaes/Build/Products/Debug-iphoneos/.../Assets.car':
- Target '...' (project '...') has compile command with input '/Users/fedor/.../.../.../Assets.xcassets'
- That command depends on command in Target '...' (project '...'): script phase “[CP] Copy Pods Resources”
There are also two warnings:
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
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.
Hai,
i have problem when i assign expandableCell into expandableCell.
delegate of two table is reference so when i click child table and want to change parent table it didnt change, the action is in expandableCell that i click not the parent table.
@younatics thanks for the update and great work!
this refractor works better than the previous git.
however, the default expandableTableView.scrollToRow(at: indexPath, at: .top, animated: true)
which works well with the old ynexpandabletableview seems to be buggy in this current build.
where should be the correct method that i should place the call?
cheers
Can try it on ExpandableCellDemo, if comment this method:
func expandableTableView(_ expandableTableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool { return true }
then all cells will not be selectable.
Conclusion, that shouldHighlightRowAt: required for cells selection
The ExpandableDelegate has no method to handle a cell after it is expanded or collapsed.
The method that does exists (didCloseRowAt) is not invoked anywhere that I could find.
Is there a way to capture a cell instance after its open or close methods are invoked, that is, after its isOpen property is set?
That would be especially handful to make changes to the cell layout based on its expanded/collapsed state.
I would suggest the creation of a delegate for the cell itself with methods that could be invoked with its open or close methods execution
I'm trying to set my table to only expand one cell at a time. I noticed that there was an attribute on the table that I could set to ".single". However, Xcode claims that "Value of type 'ExpandableTableView?' has no member 'expansionStyle'". Any suggestions?
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?
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.
I'm trying to close expanded cell when the other cell will expand? So there will be only one cell is expanded. How I could handle that please?
Hello, I'm trying to set the state of table view to expand all cells in the beginning. How can I do that?
as above.
titleForHeaderInSection and titleForFooterInSection delegate methods dont called for section 0 in grouped 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
Thanks a lot first of all for the awesome library but the indexPath I am getting in expanded cell is of row, the required indexPath in this delegate should start from 0 only then I can get correct value from array of subcategory instead it counts the expanded cell as a row which is not right. Below is my struct, everything works well except the indexPaths are messed up in the expanded cells, please fix. I might be doing something wrong too if that's the case let me know. Thanks!
Also made a video showing wrong indexPath : https://drive.google.com/open?id=10eJUTJSna282Lr_njvcQUAEpG0q7bx3_
The class file can be found here : https://drive.google.com/open?id=1iJfZGFFqK4oLvcIeMqcBZVSLXPkdAy2S
struct MenuItems{
var sectionName:String
var data:[SideMenuItems]
var numberOfItems: Int {
return data.count
}
subscript(index: Int) -> SideMenuItems {
return data[index]
}
}
struct SideMenuItems{
var name:String
var image:UIImage
var subCategoryItems:[SubCategoryItems]?
init(name:String,image:UIImage,subCategoryItems:[SubCategoryItems]) {
self.name = name
self.image = image
self.subCategoryItems = subCategoryItems
}
}
struct SubCategoryItems {
let subCat: String?
init(subCat: String) {
self.subCat = subCat
}
}
as above, how to expand one cell at a time.
Current ExpandableCell class should considered a standard implementation of a generalized protocol, in order to allow to apply the protocol to UITableViewCell when the developer doesn't want to override ExpandableCell current implementation (for whatever reason).
Since we're already mixing storyboards and code, we can just as well also add the ability to set the delegate in the storyboard:
@IBDesignable
extension ExpandableTableView {
@IBOutlet public var _expandableDelegate: AnyObject? {
get { return expandableDelegate as AnyObject }
set { expandableDelegate = newValue as? ExpandableDelegate }
}
}
Ever since I updated to the newest version, I am unable to expand my expandable cells when I click on the containing row. The selection of the row isn't being triggered and I am not getting asked for the list of table view cells anymore. I don't seem to have this issue with a normal table view and can detect selection and handle it just fine.
Before updating from the 1.1.0 pod version, I was able to actually enter the func expandableTableView(_ expandableTableView: ExpandableTableView, expandedCellsForRowAt indexPath: IndexPath) -> [UITableViewCell]?
method and return my cells; but had an issue where everything would be rendering on top of each other or just in weird locations on the table when more than 1 expandable row was expanded at a time.
Any help would be appreciated. Thanks in advance.
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
In some implementations use willDisplayCell helps do a more smoothly list.
What do you thing?
Referece: https://developer.apple.com/documentation/uikit/uitableviewdelegate/1614883-tableview
Hey, an FYI: the demo contains functions not available is the standard pull. expandAllCells() is used in the demo, but not in the currently available repo.
Would be great to have a close(at indexPath: IndexPath)
function or even better a toggle(at indexPath: IndexPath)
function.
Just a suggestion.
Thanks
Sean
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
}
Could you please let me know if this library supports nested expandable cells inside a parent expandable cell?
where to call the expandableTableView.scrollToRow(at: index, at: .top, animated: true) to get focus on expanded section?
Hi there,
I have a compile-time problem with the ExpandableTableView class. I've put in a fix for it here:
https://github.com/swiftDev1989/ExpandableCell
not sure how to create a pull request for your repo.
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
I have a tableview with 2 sections. Each section contains only one row (Completed and ongoing orders). Whenever i click on an expandable cell, it opens normally, but if it is expanded, the other one won't expand unless the first one is closed. I debugged it and it is calling the expandedCellsForRowAt and heightsForExpandedRowAt correctly and is returning all the expanded cells that should appear, but they simply won't appear. Can anyone help me please ? Thanks
By using
func expandableTableView(_ expandableTableView: ExpandableTableView, expandedCellsForRowAt indexPath: IndexPath) -> [UITableViewCell]?
and returning more than 3 cells like this:
extension DetailedViewController: ExpandableDelegate {
func expandableTableView(_ expandableTableView: ExpandableTableView, expandedCellsForRowAt indexPath: IndexPath) -> [UITableViewCell]? {
switch indexPath.section {
case 0:
switch indexPath.row {
case 0:
let cell1 = mDetailedInfoTable.dequeueReusableCell(withIdentifier: StepCountInfoCellHeader.IDENTIFIER) as! StepCountInfoCellHeader
let cell2 = mDetailedInfoTable.dequeueReusableCell(withIdentifier: StepCountInfoCell.IDENTIFIER) as! StepCountInfoCell
let cell3 = mDetailedInfoTable.dequeueReusableCell(withIdentifier: StepCountInfoCell.IDENTIFIER) as! StepCountInfoCell
let cell4 = mDetailedInfoTable.dequeueReusableCell(withIdentifier: StepCountInfoCell.IDENTIFIER) as! StepCountInfoCell
return [cell1, cell2, cell3, cell4]
causes "Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)" error.
func expandedHeight(at indexPath: IndexPath) -> CGFloat? {
for expandableData in expandableDatas {
if let index = expandableData.expandedIndexPaths.index(of: indexPath) {
return expandableData.expandedHeights[index] //<-Error occurs here
}
}
If this library can only add 3 cells, that's a serious problem.
Hey. I have 11 ExpandableCells and about 50 ExpandedCells. I am initializing it like that:
func expandableTableView(_ expandableTableView: ExpandableTableView, expandedCellsForRowAt indexPath: IndexPath) -> [UITableViewCell]? {
`var cells: [ExpandedCell] = []
for i in 0...platinumProteinMeals[indexPath.row].meals.count - 1 {
let cell = tableView.dequeueReusableCell(withIdentifier: ExpandedCell.ID) as! ExpandedCell
print("\(indexPath) | \(i) | \(platinumProteinMeals[indexPath.row].meals[i])")
cell.titleLabel.text = platinumProteinMeals[indexPath.row].meals[i]
cell.isHidden = false
cells.append(cell)
}
return cells
}`
The platinumProteinMeals is an array of 11 NDDSections, one section would look like this:
NDDSection(category: "Beef", meals: ["Beef Avocado Salad", "Beef in Chili Sauce", "Beef Soup", "Beef Steak", "Beef Tartar", "Beef with French Beans", "Chilli Lime Beef", "Thai Beef Salad"])
My issue is that the cell randomly disappears (mostly while scrolling) and a wrong meal
of themeals
array is getting displayed. For example a Turkey meal is being displayed in the Beef ExpandableCell. Any idea how to fix this? Thanks in advance
Hello,
After changing the number of expandable rows in my dataset and call reloadData, the app crashes.
This is caused by fatal error: Index out of range
from this line.
After some debugging I think that the problem is about the delegate method func expandableTableView(_ expandableTableView: ExpandableTableView, heightsForExpandedRowAt indexPath: IndexPath) -> [CGFloat]?
which is not called for each row after the dataset change.
I'm using:
XCode 9.0.1
Swift 4
ExpandableCell 1.2.0 installed with cocoapods
UPDATE
The crash seems to occur only if the updated dataset have the expandable row open when reloadData()
is called. If I call:
self.tableView.closeAll()
self.tableView.reloadData()
self.tableView.open(at: indexPath)
from the func expandableTableView(_ expandableTableView: ExpandableTableView, didSelectRowAt indexPath: IndexPath)
method all works as it should, however is not the best solution, because the row is opening, closing and opening again (and the animation will broke).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.