Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
younatics@gmail.com committed Mar 20, 2017
1 parent 1977b73 commit bc2a5de
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Updates

## [v0.2.0](https://github.com/younatics/YNExpandableCell/releases/tag/0.2.0)
* Update docs

## [v0.1.1](https://github.com/younatics/YNExpandableCell/releases/tag/0.1.1)
* Update pod spec


## [v0.1.0](https://github.com/younatics/YNExpandableCell/releases/tag/0.1.0)
* Initial Pod Commit

2 changes: 1 addition & 1 deletion YNExpandableCell.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'YNExpandableCell'
s.version = '0.1.1'
s.version = '0.2.0'
s.summary = 'Easiest way to expand and collapse cell for iOS with Swift 3'

s.description = <<-DESC
Expand Down
13 changes: 12 additions & 1 deletion YNExpandableCell/YNExpandableCell/YNExpandableCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,35 @@

import UIKit

public class YNExpandableCell: UITableViewCell {
/// Inherit YNExpandableCell when you want to use custom accessory type
public class YNExpandableCell: UITableViewCell {

/// Normal Custom Accessory Type change UIImage
public var normalCustomAccessoryType: UIImageView!

/// Selected Custom Accessory Type change UIImage
public var selectedCustomAccessoryType: UIImageView!

/// Basic Init method
public override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)

self.initView()
}

/// Basic Coder method
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

/// Basic awakeFromNib method
public override func awakeFromNib() {
super.awakeFromNib()

self.initView()
}

/// Init method. override this method whatever you like. Mainly about Custom Accessory Type
public func initView() {
let width = UIScreen.main.bounds.size.width
let height = self.frame.size.height
Expand All @@ -44,13 +53,15 @@ public class YNExpandableCell: UITableViewCell {
self.selectionStyle = .none
}

/// Normal function when cell is unclicked
public func normal() {
self.selectedCustomAccessoryType.isHidden = true
self.normalCustomAccessoryType.isHidden = false

self.rotateAnimationFrom(selectedCustomAccessoryType, toItem: normalCustomAccessoryType, duration: 0.3)
}

/// Selected function when cell is clicked
public func selected() {
self.selectedCustomAccessoryType.isHidden = false
self.normalCustomAccessoryType.isHidden = true
Expand Down
30 changes: 27 additions & 3 deletions YNExpandableCell/YNExpandableCell/YNTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,46 @@
import Foundation
import UIKit

/// Inherit this tableView to use YNExpandableCell
open class YNTableView: UITableView, UITableViewDataSource, UITableViewDelegate {
private var expandedIndexPaths = [IndexPath]()

/// Set ynDelegate to use this tableview
open var ynDelegate: YNTableViewDelegate? {
didSet {
self.delegate = self
self.dataSource = self
}
}

/// Simple UITableViewRowAnimation
open var ynTableViewRowAnimation = UITableViewRowAnimation.top

/// Called in Nib
open override func awakeFromNib() {
super.awakeFromNib()

self.initView()
}

/// Init method
public override init(frame: CGRect, style: UITableViewStyle) {
super.init(frame: frame, style: style)

self.initView()
}


/// Init coder
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

/**
Register cells with array of strings

- Parameter nibNames: [String]
- Parameter reuseIdentifiers: [String]
*/
public func registerCellsWith(nibNames: [String], and reuseIdentifiers: [String]) {
self.checkValueIsSame(first: nibNames, second: reuseIdentifiers)

Expand All @@ -46,6 +57,12 @@ open class YNTableView: UITableView, UITableViewDataSource, UITableViewDelegate
}
}

/**
Register cells with array of cells and strings

- Parameter cells: [AnyClass]
- Parameter reuseIdentifiers: [String]
*/
public func registerCellsWith(cells: [AnyClass], and reuseIdentifiers: [String]) {
self.checkValueIsSame(first: cells, second: reuseIdentifiers)

Expand All @@ -67,18 +84,23 @@ open class YNTableView: UITableView, UITableViewDataSource, UITableViewDelegate
}

//PRAGMA MARK: YNTableView Delegate


/// Basic UITableViewDelegate: func numberOfSections(in tableView: UITableView) -> Int
public func numberOfSections(in tableView: UITableView) -> Int {
guard let delegate = self.ynDelegate else { return Int() }
guard let numberOfSection = delegate.numberOfSections?(in: self) else { return Int() }
return numberOfSection
}

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
/// Basic UITableViewDelegate: func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard let delegate = self.ynDelegate else { return Int() }

return delegate.tableView(self, numberOfRowsInSection: section) + self.checkExpandRowIn(section: section)
}

/// Basic UITableViewDelegate: func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let delegate = self.ynDelegate else { return UITableViewCell() }

Expand All @@ -102,7 +124,7 @@ open class YNTableView: UITableView, UITableViewDataSource, UITableViewDelegate
return delegate.tableView(self, cellForRowAt: internalIndexPath)

}

/// Basic UITableViewDelegate: func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let delegate = self.ynDelegate else { return }

Expand All @@ -125,6 +147,7 @@ open class YNTableView: UITableView, UITableViewDataSource, UITableViewDelegate
}
}

/// Basic UITableViewDelegate: func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath)
public func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
for expandedIndexPath in self.expandedIndexPaths {
let internalIndexPath = IndexPath(row: expandedIndexPath.row - 1, section: expandedIndexPath.section)
Expand All @@ -143,6 +166,7 @@ open class YNTableView: UITableView, UITableViewDataSource, UITableViewDelegate
}
}

/// Basic UITableViewDelegate: func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat
public func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
Expand Down
8 changes: 8 additions & 0 deletions YNExpandableCell/YNExpandableCell/YNTableViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
import Foundation
import UIKit

/// You need to set delegate and add only one method.
public protocol YNTableViewDelegate: UITableViewDelegate, UITableViewDataSource {

/**
Determine expandable cell in this view. This method is all that you have to do

- Parameter tableView: YNTableView
- Parameter expandCellAt: Determine expandable cell and return UITableViewCell
*/
func tableView(_ tableView: YNTableView, expandCellAt indexPath: IndexPath) -> UITableViewCell?
}
3 changes: 3 additions & 0 deletions YNExpandableCell/YNExpandableCell/YNTableViewExtenstion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@
import UIKit

extension YNTableView {
/// Basic UITableViewDelegate: func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
public func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
guard let delegate = self.ynDelegate else { return nil }
guard let titleForHeaderInSection = delegate.tableView?(self, titleForHeaderInSection: section) else { return nil }

return titleForHeaderInSection
}

/// Basic UITableViewDelegate: func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
guard let delegate = self.ynDelegate else { return CGFloat() }
guard let heightForHeaderInSection = delegate.tableView?(self, heightForHeaderInSection: section) else { return CGFloat() }

return heightForHeaderInSection
}

/// Basic UITableViewDelegate: func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
public func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
guard let delegate = self.ynDelegate else { return nil }
guard let viewForHeaderInSection = delegate.tableView?(self, viewForHeaderInSection: section) else { return nil }
Expand Down

0 comments on commit bc2a5de

Please sign in to comment.