Skip to content
This repository has been archived by the owner on Nov 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request #23 from okhanokbay/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
okhanokbay authored Mar 8, 2018
2 parents b81a330 + 565ee0b commit 37c4969
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 118 deletions.
17 changes: 10 additions & 7 deletions Example/ExpyTableView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0820;
DevelopmentTeam = VR8AX8Y52G;
LastSwiftMigration = 0910;
ProvisioningStyle = Automatic;
};
607FACE41AFB9204008FA782 = {
Expand Down Expand Up @@ -538,14 +539,15 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = VR8AX8Y52G;
INFOPLIST_FILE = ExpyTableView/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.ExpyTableView-ExampleProject";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -556,14 +558,15 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = VR8AX8Y52G;
INFOPLIST_FILE = ExpyTableView/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.ExpyTableView-ExampleProject";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
6 changes: 5 additions & 1 deletion Example/ExpyTableView/BasicExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BasicExampleViewController: UIViewController {
//All you have to do is to implement this method. If you have a current table view which is not expandable, you can turn it into an expandable table view just by copying and pasting the code for first cell from cellForRowAtIndexPath method.

extension BasicExampleViewController: ExpyTableViewDataSource {
func expandableCell(forSection section: Int, inTableView tableView: ExpyTableView) -> UITableViewCell {
func tableView(_ tableView: ExpyTableView, expandableCellForSection section: Int) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: HeaderTableViewCell.self)) as! HeaderTableViewCell
//Make your customizations here.
cell.labelHeader.text = "Section: \(section) Row: 0"
Expand All @@ -44,6 +44,10 @@ extension BasicExampleViewController {
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Please see https://github.com/okhanokbay/ExpyTableView/issues/12
// The cell instance that you return from expandableCellForSection: data source method is actually the first row of belonged section. Thus, when you return 4 from numberOfRowsInSection data source method, first row refers to expandable cell and the other 3 rows refer to other rows in this section.
// So, always return the total row count you want to see in that section

return 4
}

Expand Down
16 changes: 8 additions & 8 deletions Example/ExpyTableView/CustomizationExampleUsedClasses.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ class PhoneNameTableViewCell: UITableViewCell, ExpyTableViewHeaderCell{
}

private func arrowDown(animated: Bool) {
UIView.animate(withDuration: (animated ? 0.3 : 0)) { [weak self] _ in
self?.imageViewArrow.transform = CGAffineTransform(rotationAngle: (CGFloat.pi / 2))
UIView.animate(withDuration: (animated ? 0.3 : 0)) {
self.imageViewArrow.transform = CGAffineTransform(rotationAngle: (CGFloat.pi / 2))
}
}

private func arrowRight(animated: Bool) {
UIView.animate(withDuration: (animated ? 0.3 : 0)) { [weak self] _ in
self?.imageViewArrow.transform = CGAffineTransform(rotationAngle: 0)
UIView.animate(withDuration: (animated ? 0.3 : 0)) {
self.imageViewArrow.transform = CGAffineTransform(rotationAngle: 0)
}
}
}
Expand All @@ -59,14 +59,14 @@ class BuyTableViewCell: UITableViewCell {}
extension UITableViewCell {

func showSeparator() {
DispatchQueue.main.async { [weak self] _ in
self?.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
DispatchQueue.main.async {
self.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
}

func hideSeparator() {
DispatchQueue.main.async { [weak self] in
self?.separatorInset = UIEdgeInsets(top: 0, left: UIScreen.main.bounds.size.width, bottom: 0, right: 0)
DispatchQueue.main.async {
self.separatorInset = UIEdgeInsets(top: 0, left: self.bounds.size.width, bottom: 0, right: 0)
}
}
}
13 changes: 9 additions & 4 deletions Example/ExpyTableView/CustomizationExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,20 @@ class CustomizationExampleViewController: UIViewController {
@objc private func orientationDidChange() {
switch UIDevice.current.orientation {
case .portrait, .portraitUpsideDown, .landscapeLeft, .landscapeRight:
expandableTableView.reloadSections(IndexSet(Array(expandableTableView.visibleSections.keys)), with: .none)
expandableTableView.reloadSections(IndexSet(Array(expandableTableView.expandedSections.keys)), with: .none)
default:break
}
}
}

//MARK: ExpyTableViewDataSourceMethods
extension CustomizationExampleViewController: ExpyTableViewDataSource {
func canExpand(section: Int, inTableView tableView: ExpyTableView) -> Bool {

func tableView(_ tableView: ExpyTableView, canExpandSection section: Int) -> Bool {
return true
}
func expandableCell(forSection section: Int, inTableView tableView: ExpyTableView) -> UITableViewCell {

func tableView(_ tableView: ExpyTableView, expandableCellForSection section: Int) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: PhoneNameTableViewCell.self)) as! PhoneNameTableViewCell
cell.labelPhoneName.text = sampleData[section].first!
cell.layoutMargins = UIEdgeInsets.zero
Expand Down Expand Up @@ -143,6 +144,10 @@ extension CustomizationExampleViewController {
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Please see https://github.com/okhanokbay/ExpyTableView/issues/12
// The cell instance that you return from expandableCellForSection: data source method is actually the first row of belonged section. Thus, when you return 4 from numberOfRowsInSection data source method, first row refers to expandable cell and the other 3 rows refer to other rows in this section.
// So, always return the total row count you want to see in that section

print("Row count for section \(section) is \(sampleData[section].count)")
return sampleData[section].count + 1 // +1 here is for BuyTableViewCell
}
Expand Down
5 changes: 2 additions & 3 deletions Example/ExpyTableView/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import UIKit

class MainViewController: UIViewController {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Expy Examples"
}
}
21 changes: 16 additions & 5 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions ExpyTableView/Classes/ExpyAbstractions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// ExpyAbstractions.swift
// ExpyTableView
//
// Created by Okhan on 08/03/2018.
//

import Foundation

public struct ExpyTableViewDefaultValues {
public static let expandableStatus = true
public static let expandingAnimation: UITableViewRowAnimation = .fade
public static let collapsingAnimation: UITableViewRowAnimation = .fade
}

public enum ExpyState: Int {
case willExpand, willCollapse, didExpand, didCollapse
}

public enum ExpyActionType {
case expand, collapse
}

public protocol ExpyTableViewHeaderCell: class {
func changeState(_ state: ExpyState, cellReuseStatus cellReuse: Bool)
}

public protocol ExpyTableViewDataSource: UITableViewDataSource {
func tableView(_ tableView: ExpyTableView, canExpandSection section: Int) -> Bool
func tableView(_ tableView: ExpyTableView, expandableCellForSection section: Int) -> UITableViewCell
}

public extension ExpyTableViewDataSource {
func tableView(_ tableView: ExpyTableView, canExpandSection section: Int) -> Bool {
return ExpyTableViewDefaultValues.expandableStatus
}
}

public protocol ExpyTableViewDelegate: UITableViewDelegate {
func tableView(_ tableView: ExpyTableView, expyState state: ExpyState, changeForSection section: Int)
}

public extension ExpyTableViewDelegate {
func tableView(_ tableView: ExpyTableView, expyState state: ExpyState, changeForSection section: Int) {}
}
Loading

0 comments on commit 37c4969

Please sign in to comment.