Skip to content

Commit

Permalink
fix: TableView & CollectionView, header & footer 是否存在加入到判空逻辑中.
Browse files Browse the repository at this point in the history
  • Loading branch information
linhay committed Jul 11, 2021
1 parent e053acb commit 56104c2
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 41 deletions.
2 changes: 1 addition & 1 deletion EmptyPage.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'EmptyPage'
s.version = '4.0.6'
s.version = '4.0.7'
s.summary = 'iOS - 轻量级空白页占位图框架...'

s.homepage = 'https://github.com/linhay/EmptyPage'
Expand Down
48 changes: 42 additions & 6 deletions Example/EmptyPage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 52;
objects = {

/* Begin PBXBuildFile section */
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
CD0713B2269AC24E00923F03 /* TestReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD0713B1269AC24E00923F03 /* TestReusableView.swift */; };
CD0713C1269AC53500923F03 /* Stem in Frameworks */ = {isa = PBXBuildFile; productRef = CD0713C0269AC53500923F03 /* Stem */; };
CD87ED8025061A7200468FD7 /* Example.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD87ED7F25061A7200468FD7 /* Example.swift */; };
CD87EDB825067D3C00468FD7 /* TestTableViewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD87EDB725067D3C00468FD7 /* TestTableViewViewController.swift */; };
CD87EDBC2506812500468FD7 /* TestCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD87EDBB2506812500468FD7 /* TestCollectionViewController.swift */; };
Expand Down Expand Up @@ -44,6 +46,7 @@
7A0D4B6758498EB40AB7A721 /* Pods_EmptyPage_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_EmptyPage_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
A530BC265F9B925295F14521 /* Pods_EmptyPage_Objective_C.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_EmptyPage_Objective_C.framework; sourceTree = BUILT_PRODUCTS_DIR; };
A6E3A5E7C2782BD08A8AD275 /* Pods_EmptyPage_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_EmptyPage_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
CD0713B1269AC24E00923F03 /* TestReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestReusableView.swift; sourceTree = "<group>"; };
CD87ED7F25061A7200468FD7 /* Example.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Example.swift; sourceTree = "<group>"; };
CD87EDB725067D3C00468FD7 /* TestTableViewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestTableViewViewController.swift; sourceTree = "<group>"; };
CD87EDBB2506812500468FD7 /* TestCollectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestCollectionViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -81,6 +84,7 @@
buildActionMask = 2147483647;
files = (
D1DA711524FFBB055DF9A88D /* Pods_EmptyPage_Example.framework in Frameworks */,
CD0713C1269AC53500923F03 /* Stem in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -182,6 +186,7 @@
CDAB9EDA250103530013ACEF /* TestStateViewController.xib */,
CD87EDB725067D3C00468FD7 /* TestTableViewViewController.swift */,
CD87EDBB2506812500468FD7 /* TestCollectionViewController.swift */,
CD0713B1269AC24E00923F03 /* TestReusableView.swift */,
);
path = tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -216,6 +221,9 @@
dependencies = (
);
name = EmptyPage_Example;
packageProductDependencies = (
CD0713C0269AC53500923F03 /* Stem */,
);
productName = EmptyPage;
productReference = 607FACD01AFB9204008FA782 /* EmptyPage_Example.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -246,6 +254,9 @@
Base,
);
mainGroup = 607FACC71AFB9204008FA782;
packageReferences = (
CD0713BF269AC53500923F03 /* XCRemoteSwiftPackageReference "Stem" */,
);
productRefGroup = 607FACD11AFB9204008FA782 /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -358,7 +369,6 @@
"${BUILT_PRODUCTS_DIR}/MJRefresh/MJRefresh.framework",
"${BUILT_PRODUCTS_DIR}/ReachabilitySwift/Reachability.framework",
"${BUILT_PRODUCTS_DIR}/SnapKit/SnapKit.framework",
"${BUILT_PRODUCTS_DIR}/Stem/Stem.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
Expand All @@ -367,7 +377,6 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MJRefresh.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SnapKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Stem.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down Expand Up @@ -398,6 +407,7 @@
CD9C189A2498E51700FC0DE9 /* IndexViewController.swift in Sources */,
CDF1DE15249A550F0037F7ED /* DZNEmptyDataSetSection.swift in Sources */,
CD87ED8025061A7200468FD7 /* Example.swift in Sources */,
CD0713B2269AC24E00923F03 /* TestReusableView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -507,7 +517,8 @@
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 5.0;
VALIDATE_PRODUCT = YES;
};
Expand All @@ -522,7 +533,10 @@
DEVELOPMENT_TEAM = 8H2PX2432F;
INFOPLIST_FILE = EmptyPage/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = linhey.EmptyPage;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -541,7 +555,10 @@
DEVELOPMENT_TEAM = 8H2PX2432F;
INFOPLIST_FILE = EmptyPage/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = linhey.EmptyPage;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -573,6 +590,25 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
CD0713BF269AC53500923F03 /* XCRemoteSwiftPackageReference "Stem" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/linhay/Stem.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.0.41;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
CD0713C0269AC53500923F03 /* Stem */ = {
isa = XCSwiftPackageProductDependency;
package = CD0713BF269AC53500923F03 /* XCRemoteSwiftPackageReference "Stem" */;
productName = Stem;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 607FACC81AFB9204008FA782 /* Project object */;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"object": {
"pins": [
{
"package": "Stem",
"repositoryURL": "https://github.com/linhay/Stem.git",
"state": {
"branch": null,
"revision": "311f1357e4c8463207c666a40dc2929b51438a31",
"version": "0.0.41"
}
}
]
},
"version": 1
}
48 changes: 48 additions & 0 deletions Example/EmptyPage/tests/TestCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,52 @@ fileprivate class TestSection<Cell: UICollectionViewCell>: SectionCollectionProt
open func config(models: [Cell.Model]) {
self.models = models
}

var hiddenHeaderWhenNoItem: Bool = false
var hiddenFooterWhenNoItem: Bool = false

var showHeader = true
var showFooter = true

var headerView: UICollectionReusableView? {
guard showHeader else {
return nil
}
let view = dequeue(kind: .header) as TestReusableView
view.backgroundColor = .red
view.st.onTapGesture {
self.showHeader = false
self.reload()
}
return view
}

var headerSize: CGSize {
guard showHeader else {
return .zero
}
return .init(width: sectionView.bounds.width, height: 44)
}

var footerView: UICollectionReusableView? {
guard showFooter else {
return nil
}
let view = dequeue(kind: .footer) as TestReusableView
view.backgroundColor = .blue
view.st.onTapGesture {
self.showFooter = false
self.reload()
}
return view
}

var footerSize: CGSize {
guard showFooter else {
return .zero
}
return .init(width: sectionView.bounds.width, height: 44)
}

open func itemSize(at row: Int) -> CGSize {
let width = sectionView.bounds.width - sectionInset.left - sectionInset.right
Expand All @@ -108,6 +154,8 @@ fileprivate class TestSection<Cell: UICollectionViewCell>: SectionCollectionProt

open func config(sectionView: UICollectionView) {
sectionView.st.register(Cell.self)
sectionView.st.register(TestReusableView.self, for: .footer)
sectionView.st.register(TestReusableView.self, for: .header)
}

open func item(at row: Int) -> UICollectionViewCell {
Expand Down
14 changes: 14 additions & 0 deletions Example/EmptyPage/tests/TestReusableView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// TestUIReusableView.swift
// EmptyPage_Example
//
// Created by linhey on 2021/7/11.
// Copyright © 2021 CocoaPods. All rights reserved.
//

import UIKit
import Stem

class TestReusableView: UICollectionReusableView, STViewProtocol {

}
39 changes: 39 additions & 0 deletions Example/EmptyPage/tests/TestTableViewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,45 @@ fileprivate class TestSection<Cell: UITableViewCell>: SectionTableProtocol where
selectedEvent.call(models[row])
}

var showHeader = true
var showFooter = true

var headerView: UITableViewHeaderFooterView? {
guard showHeader else {
return nil
}
let header = UITableViewHeaderFooterView(frame: .init(origin: .zero,
size: .init(width: sectionView.bounds.width, height: 44)))
header.st.onTapGesture {
self.showHeader = false
self.reload()
}
header.contentView.backgroundColor = .red
return header
}

var headerHeight: CGFloat {
return 44
}

var footerView: UITableViewHeaderFooterView? {
guard showFooter else {
return nil
}
let footer = UITableViewHeaderFooterView(frame: .init(origin: .zero,
size: .init(width: sectionView.bounds.width, height: 44)))
footer.st.onTapGesture {
self.showFooter = false
self.reload()
}
footer.contentView.backgroundColor = .blue
return footer
}

var footerHeight: CGFloat {
return 44
}

open func itemHeight(at row: Int) -> CGFloat {
let width = sectionView.bounds.width
return Cell.preferredSize(limit: .init(width: width,
Expand Down
1 change: 0 additions & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ target 'EmptyPage_Example' do
pod 'ReachabilitySwift'
pod 'EmptyPage', :path => '../EmptyPage.podspec'
pod 'SnapKit', '5.0.0'
pod 'Stem', '0.0.33'
pod 'MJRefresh'
pod 'LookinServer', :configurations => ['Debug']
pod 'SwiftLint'
Expand Down
36 changes: 9 additions & 27 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
PODS:
- EmptyPage (4.0.4):
- EmptyPage/core (= 4.0.4)
- EmptyPage/managers (= 4.0.4)
- EmptyPage/templates (= 4.0.4)
- EmptyPage/core (4.0.4)
- EmptyPage/managers (4.0.4):
- EmptyPage (4.0.6):
- EmptyPage/core (= 4.0.6)
- EmptyPage/managers (= 4.0.6)
- EmptyPage/templates (= 4.0.6)
- EmptyPage/core (4.0.6)
- EmptyPage/managers (4.0.6):
- EmptyPage/core
- EmptyPage/templates (4.0.4):
- EmptyPage/templates (4.0.6):
- EmptyPage/core
- LookinServer (1.0.0)
- MJRefresh (3.4.3)
- ReachabilitySwift (5.0.0)
- SnapKit (5.0.0)
- Stem (0.0.33):
- Stem/Core (= 0.0.33)
- Stem/CrossPlatform (= 0.0.33)
- Stem/STUIKit (= 0.0.33)
- Stem/UIKit (= 0.0.33)
- Stem/Core (0.0.33)
- Stem/CrossPlatform (0.0.33):
- Stem/Core
- Stem/STUIKit (0.0.33):
- Stem/Core
- Stem/CrossPlatform
- Stem/UIKit
- Stem/UIKit (0.0.33):
- Stem/Core
- Stem/CrossPlatform
- SwiftLint (0.39.2)

DEPENDENCIES:
Expand All @@ -35,7 +20,6 @@ DEPENDENCIES:
- MJRefresh
- ReachabilitySwift
- SnapKit (= 5.0.0)
- Stem (= 0.0.33)
- SwiftLint

SPEC REPOS:
Expand All @@ -44,22 +28,20 @@ SPEC REPOS:
- MJRefresh
- ReachabilitySwift
- SnapKit
- Stem
- SwiftLint

EXTERNAL SOURCES:
EmptyPage:
:path: "../EmptyPage.podspec"

SPEC CHECKSUMS:
EmptyPage: 17156498ded7bac7a89d4e47468ad2f78d88664a
EmptyPage: 7ad053cf08b4aebd60547e54baec8a028a440d0d
LookinServer: 0002891cd3cec5e082a910e897dfe71b4f06b89e
MJRefresh: 53e3e3219f204425ee6d3e62e8733d3295944cd6
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
SnapKit: fd22d10eb9aff484d79a8724eab922c1ddf89bcf
Stem: 4cff14a2aa3febfb7e1aff2163b4f684e8fa9e34
SwiftLint: 22ccbbe3b8008684be5955693bab135e0ed6a447

PODFILE CHECKSUM: cd174a9c35e3f255b701798021a94f485f4203b2
PODFILE CHECKSUM: 81f1d9fb54b49749c06a7975852951a4bfc0ed95

COCOAPODS: 1.10.1
Loading

0 comments on commit 56104c2

Please sign in to comment.