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

Commit 37c4969

Browse files
authored
Merge pull request #23 from okhanokbay/develop
Merge develop into master
2 parents b81a330 + 565ee0b commit 37c4969

File tree

8 files changed

+166
-118
lines changed

8 files changed

+166
-118
lines changed

Example/ExpyTableView.xcodeproj/project.pbxproj

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@
257257
TargetAttributes = {
258258
607FACCF1AFB9204008FA782 = {
259259
CreatedOnToolsVersion = 6.3.1;
260-
LastSwiftMigration = 0820;
260+
DevelopmentTeam = VR8AX8Y52G;
261+
LastSwiftMigration = 0910;
261262
ProvisioningStyle = Automatic;
262263
};
263264
607FACE41AFB9204008FA782 = {
@@ -538,14 +539,15 @@
538539
buildSettings = {
539540
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
540541
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
541-
DEVELOPMENT_TEAM = "";
542+
DEVELOPMENT_TEAM = VR8AX8Y52G;
542543
INFOPLIST_FILE = ExpyTableView/Info.plist;
543544
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
544545
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
545546
MODULE_NAME = ExampleApp;
546-
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
547+
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.ExpyTableView-ExampleProject";
547548
PRODUCT_NAME = "$(TARGET_NAME)";
548-
SWIFT_VERSION = 3.0;
549+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
550+
SWIFT_VERSION = 4.0;
549551
TARGETED_DEVICE_FAMILY = "1,2";
550552
};
551553
name = Debug;
@@ -556,14 +558,15 @@
556558
buildSettings = {
557559
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
558560
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
559-
DEVELOPMENT_TEAM = "";
561+
DEVELOPMENT_TEAM = VR8AX8Y52G;
560562
INFOPLIST_FILE = ExpyTableView/Info.plist;
561563
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
562564
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
563565
MODULE_NAME = ExampleApp;
564-
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
566+
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.ExpyTableView-ExampleProject";
565567
PRODUCT_NAME = "$(TARGET_NAME)";
566-
SWIFT_VERSION = 3.0;
568+
SWIFT_SWIFT3_OBJC_INFERENCE = On;
569+
SWIFT_VERSION = 4.0;
567570
TARGETED_DEVICE_FAMILY = "1,2";
568571
};
569572
name = Release;

Example/ExpyTableView/BasicExampleViewController.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class BasicExampleViewController: UIViewController {
2828
//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.
2929

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

4646
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
47+
// Please see https://github.com/okhanokbay/ExpyTableView/issues/12
48+
// 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.
49+
// So, always return the total row count you want to see in that section
50+
4751
return 4
4852
}
4953

Example/ExpyTableView/CustomizationExampleUsedClasses.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ class PhoneNameTableViewCell: UITableViewCell, ExpyTableViewHeaderCell{
3838
}
3939

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

4646
private func arrowRight(animated: Bool) {
47-
UIView.animate(withDuration: (animated ? 0.3 : 0)) { [weak self] _ in
48-
self?.imageViewArrow.transform = CGAffineTransform(rotationAngle: 0)
47+
UIView.animate(withDuration: (animated ? 0.3 : 0)) {
48+
self.imageViewArrow.transform = CGAffineTransform(rotationAngle: 0)
4949
}
5050
}
5151
}
@@ -59,14 +59,14 @@ class BuyTableViewCell: UITableViewCell {}
5959
extension UITableViewCell {
6060

6161
func showSeparator() {
62-
DispatchQueue.main.async { [weak self] _ in
63-
self?.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
62+
DispatchQueue.main.async {
63+
self.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
6464
}
6565
}
6666

6767
func hideSeparator() {
68-
DispatchQueue.main.async { [weak self] in
69-
self?.separatorInset = UIEdgeInsets(top: 0, left: UIScreen.main.bounds.size.width, bottom: 0, right: 0)
68+
DispatchQueue.main.async {
69+
self.separatorInset = UIEdgeInsets(top: 0, left: self.bounds.size.width, bottom: 0, right: 0)
7070
}
7171
}
7272
}

Example/ExpyTableView/CustomizationExampleViewController.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,20 @@ class CustomizationExampleViewController: UIViewController {
7070
@objc private func orientationDidChange() {
7171
switch UIDevice.current.orientation {
7272
case .portrait, .portraitUpsideDown, .landscapeLeft, .landscapeRight:
73-
expandableTableView.reloadSections(IndexSet(Array(expandableTableView.visibleSections.keys)), with: .none)
73+
expandableTableView.reloadSections(IndexSet(Array(expandableTableView.expandedSections.keys)), with: .none)
7474
default:break
7575
}
7676
}
7777
}
7878

7979
//MARK: ExpyTableViewDataSourceMethods
8080
extension CustomizationExampleViewController: ExpyTableViewDataSource {
81-
func canExpand(section: Int, inTableView tableView: ExpyTableView) -> Bool {
81+
82+
func tableView(_ tableView: ExpyTableView, canExpandSection section: Int) -> Bool {
8283
return true
8384
}
84-
85-
func expandableCell(forSection section: Int, inTableView tableView: ExpyTableView) -> UITableViewCell {
85+
86+
func tableView(_ tableView: ExpyTableView, expandableCellForSection section: Int) -> UITableViewCell {
8687
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: PhoneNameTableViewCell.self)) as! PhoneNameTableViewCell
8788
cell.labelPhoneName.text = sampleData[section].first!
8889
cell.layoutMargins = UIEdgeInsets.zero
@@ -143,6 +144,10 @@ extension CustomizationExampleViewController {
143144
}
144145

145146
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
147+
// Please see https://github.com/okhanokbay/ExpyTableView/issues/12
148+
// 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.
149+
// So, always return the total row count you want to see in that section
150+
146151
print("Row count for section \(section) is \(sampleData[section].count)")
147152
return sampleData[section].count + 1 // +1 here is for BuyTableViewCell
148153
}

Example/ExpyTableView/MainViewController.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
import UIKit
1010

1111
class MainViewController: UIViewController {
12-
13-
override func viewWillAppear(_ animated: Bool) {
14-
super.viewWillAppear(animated)
12+
override func viewDidLoad() {
13+
super.viewDidLoad()
1514
navigationItem.title = "Expy Examples"
1615
}
1716
}

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 16 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// ExpyAbstractions.swift
3+
// ExpyTableView
4+
//
5+
// Created by Okhan on 08/03/2018.
6+
//
7+
8+
import Foundation
9+
10+
public struct ExpyTableViewDefaultValues {
11+
public static let expandableStatus = true
12+
public static let expandingAnimation: UITableViewRowAnimation = .fade
13+
public static let collapsingAnimation: UITableViewRowAnimation = .fade
14+
}
15+
16+
public enum ExpyState: Int {
17+
case willExpand, willCollapse, didExpand, didCollapse
18+
}
19+
20+
public enum ExpyActionType {
21+
case expand, collapse
22+
}
23+
24+
public protocol ExpyTableViewHeaderCell: class {
25+
func changeState(_ state: ExpyState, cellReuseStatus cellReuse: Bool)
26+
}
27+
28+
public protocol ExpyTableViewDataSource: UITableViewDataSource {
29+
func tableView(_ tableView: ExpyTableView, canExpandSection section: Int) -> Bool
30+
func tableView(_ tableView: ExpyTableView, expandableCellForSection section: Int) -> UITableViewCell
31+
}
32+
33+
public extension ExpyTableViewDataSource {
34+
func tableView(_ tableView: ExpyTableView, canExpandSection section: Int) -> Bool {
35+
return ExpyTableViewDefaultValues.expandableStatus
36+
}
37+
}
38+
39+
public protocol ExpyTableViewDelegate: UITableViewDelegate {
40+
func tableView(_ tableView: ExpyTableView, expyState state: ExpyState, changeForSection section: Int)
41+
}
42+
43+
public extension ExpyTableViewDelegate {
44+
func tableView(_ tableView: ExpyTableView, expyState state: ExpyState, changeForSection section: Int) {}
45+
}

0 commit comments

Comments
 (0)