Skip to content

Commit ad18010

Browse files
committed
- 优化分类。
1 parent ffc7bd9 commit ad18010

File tree

5 files changed

+47
-52
lines changed

5 files changed

+47
-52
lines changed

Example/Example.xcodeproj/project.pbxproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,9 @@
824824
buildSettings = {
825825
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
826826
CLANG_ENABLE_MODULES = YES;
827-
CODE_SIGN_STYLE = Automatic;
827+
CODE_SIGN_IDENTITY = "iPhone Developer";
828+
CODE_SIGN_STYLE = Manual;
829+
DEVELOPMENT_TEAM = JURK72AKL4;
828830
INFOPLIST_FILE = Example/Info.plist;
829831
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
830832
LD_RUNPATH_SEARCH_PATHS = (
@@ -833,6 +835,7 @@
833835
);
834836
PRODUCT_BUNDLE_IDENTIFIER = com.liangdahong.Example;
835837
PRODUCT_NAME = Example;
838+
PROVISIONING_PROFILE_SPECIFIER = wildcard;
836839
SWIFT_OBJC_BRIDGING_HEADER = "Example/Example-Bridging-Header.h";
837840
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
838841
SWIFT_VERSION = 5.0;
@@ -846,7 +849,9 @@
846849
buildSettings = {
847850
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
848851
CLANG_ENABLE_MODULES = YES;
849-
CODE_SIGN_STYLE = Automatic;
852+
CODE_SIGN_IDENTITY = "iPhone Developer";
853+
CODE_SIGN_STYLE = Manual;
854+
DEVELOPMENT_TEAM = JURK72AKL4;
850855
INFOPLIST_FILE = Example/Info.plist;
851856
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
852857
LD_RUNPATH_SEARCH_PATHS = (
@@ -855,6 +860,7 @@
855860
);
856861
PRODUCT_BUNDLE_IDENTIFIER = com.liangdahong.Example;
857862
PRODUCT_NAME = Example;
863+
PROVISIONING_PROFILE_SPECIFIER = wildcard;
858864
SWIFT_OBJC_BRIDGING_HEADER = "Example/Example-Bridging-Header.h";
859865
SWIFT_VERSION = 5.0;
860866
TARGETED_DEVICE_FAMILY = "1,2";

UITableViewDynamicLayoutCacheHeight.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'UITableViewDynamicLayoutCacheHeight'
3-
s.version = '5.1.3'
3+
s.version = '5.1.4'
44
s.summary = '🖖 Template auto layout cell for automatically UITableViewCell UITableViewHeaderFooterView calculating and cache height framework.'
55
s.homepage = 'https://github.com/liangdahong/UITableViewDynamicLayoutCacheHeight'
66
s.license = 'MIT'

UITableViewDynamicLayoutCacheHeight/Classes/UITableViewCell+BMDynamicLayout.m

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#import "UITableViewCell+BMDynamicLayout.h"
2424
#import <objc/runtime.h>
2525
#import "UITableView+BMPrivate.h"
26+
#import "UITableViewDynamicLayoutCacheHeight.h"
2627

2728
@implementation UITableViewCell (BMDynamicLayout)
2829

@@ -36,37 +37,31 @@ - (void)setBm_maxYViewFixed:(BOOL)bm_maxYViewFixed {
3637

3738
+ (instancetype)bm_tableViewCellFromNibWithTableView:(UITableView *)tableView {
3839
NSString *selfClassName = NSStringFromClass(self.class);
39-
NSString *reuseIdentifier = [selfClassName stringByAppendingString:@"BMDynamicLayoutReuseIdentifier"];
40-
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
41-
if (cell) {
42-
return cell;
43-
}
44-
45-
NSBundle *bundle = [NSBundle bundleForClass:self.class];
46-
NSString *path = [bundle pathForResource:kSwiftClassNibName(selfClassName) ofType:@"nib"];
47-
if (path.length == 0) {
48-
NSAssert(NO, @"你的 Cell 不是 IB 创建的");
49-
return nil;
50-
}
40+
NSString *reuseIdentifier = [selfClassName stringByAppendingString:@"BMNibDynamicLayoutReuseIdentifier"];
5141

52-
NSArray <UITableViewCell *> *arr = [[UINib nibWithNibName:kSwiftClassNibName(selfClassName) bundle:bundle] instantiateWithOwner:nil options:nil];
53-
for (UITableViewCell *obj in arr) {
54-
if ([obj isMemberOfClass:self.class]) {
55-
cell = obj;
56-
[cell setValue:reuseIdentifier forKey:@"reuseIdentifier"];
57-
return cell;
58-
}
42+
if ([objc_getAssociatedObject(tableView, (__bridge const void * _Nonnull)(self)) boolValue]) {
43+
// 已注册
44+
return [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
5945
}
60-
NSAssert(NO, @"你的 Cell 不是 IB 创建的");
61-
return nil;
46+
BM_UITableView_DynamicLayout_LOG(@"✅✅✅✅%@ UINib nibWithNibName", self);
47+
// 未注册,开始注册
48+
UINib *nib = [UINib nibWithNibName:kSwiftClassNibName(selfClassName) bundle:[NSBundle bundleForClass:self.class]];
49+
[tableView registerNib:nib forCellReuseIdentifier:reuseIdentifier];
50+
objc_setAssociatedObject(tableView, (__bridge const void * _Nonnull)(self), @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
51+
return [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
6252
}
6353

6454
+ (instancetype)bm_tableViewCellFromAllocWithTableView:(UITableView *)tableView {
6555
return [self bm_tableViewCellFromAllocWithTableView:tableView style:(UITableViewCellStyleDefault)];
6656
}
6757

6858
+ (instancetype)bm_tableViewCellFromAllocWithTableView:(UITableView *)tableView style:(UITableViewCellStyle)style {
69-
NSString *reuseIdentifier = [NSStringFromClass(self.class) stringByAppendingString:@"BMDynamicLayoutReuseIdentifier"];
59+
NSString *reuseIdentifier = [NSStringFromClass(self.class) stringByAppendingString:@"BMAllocDynamicLayoutReuseIdentifier"];
60+
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
61+
if (cell) {
62+
return cell;
63+
}
64+
BM_UITableView_DynamicLayout_LOG(@"✅✅✅✅%@ alloc initWithStyle", self);
7065
return [[self alloc] initWithStyle:style reuseIdentifier:reuseIdentifier];
7166
}
7267

UITableViewDynamicLayoutCacheHeight/Classes/UITableViewDynamicLayoutCacheHeight.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// SOFTWARE.
2222

2323
////////////////
24-
/// v5.1.3
24+
/// v5.1.4
2525
////////////////
2626

2727
#ifndef UITableViewDynamicLayoutCacheHeight_h

UITableViewDynamicLayoutCacheHeight/Classes/UITableViewHeaderFooterView+BMDynamicLayout.m

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#import "UITableViewHeaderFooterView+BMDynamicLayout.h"
2424
#import <objc/runtime.h>
2525
#import "UITableView+BMPrivate.h"
26+
#import "UITableViewDynamicLayoutCacheHeight.h"
2627

2728
@implementation UITableViewHeaderFooterView (BMDynamicLayout)
2829

@@ -36,38 +37,31 @@ - (void)setBm_maxYViewFixed:(BOOL)bm_maxYViewFixed {
3637

3738
+ (instancetype)bm_tableViewHeaderFooterViewFromNibWithTableView:(UITableView *)tableView {
3839
NSString *selfClassName = NSStringFromClass(self.class);
39-
NSString *reuseIdentifier = [selfClassName stringByAppendingString:@"BMDynamicLayoutReuseIdentifier"];
40-
UITableViewHeaderFooterView *headerFooterView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:reuseIdentifier];
41-
if (headerFooterView) {
42-
return headerFooterView;
40+
NSString *reuseIdentifier = [selfClassName stringByAppendingString:@"BMNibDynamicLayoutReuseIdentifier"];
41+
if ([objc_getAssociatedObject(tableView, (__bridge const void * _Nonnull)(object_getClass(self))) boolValue]) {
42+
// 已注册
43+
return [tableView dequeueReusableHeaderFooterViewWithIdentifier:reuseIdentifier];
4344
}
44-
45-
NSBundle *bundle = [NSBundle bundleForClass:self.class];
46-
NSString *path = [bundle pathForResource:kSwiftClassNibName(selfClassName) ofType:@"nib"];
47-
if (path.length == 0) {
48-
NSAssert(NO, @"你的 UITableViewHeaderFooterView 不是 IB 创建的");
49-
return nil;
50-
}
51-
NSArray <UITableViewHeaderFooterView *> *arr = [[UINib nibWithNibName:kSwiftClassNibName(selfClassName) bundle:bundle] instantiateWithOwner:nil options:nil];
52-
for (UITableViewHeaderFooterView *obj in arr) {
53-
if ([obj isMemberOfClass:self.class]) {
54-
headerFooterView = obj;
55-
[headerFooterView setValue:reuseIdentifier forKey:@"reuseIdentifier"];
56-
return headerFooterView;
57-
}
58-
}
59-
NSAssert(NO, @"你的 UITableViewHeaderFooterView 不是 IB 创建的");
60-
return nil;
45+
BM_UITableView_DynamicLayout_LOG(@"✅✅✅✅%@ UINib nibWithNibName", self);
46+
// 未注册,开始注册
47+
UINib *nib = [UINib nibWithNibName:kSwiftClassNibName(selfClassName) bundle:[NSBundle bundleForClass:self.class]];
48+
[tableView registerNib:nib forHeaderFooterViewReuseIdentifier:reuseIdentifier];
49+
objc_setAssociatedObject(tableView, (__bridge const void * _Nonnull)(object_getClass(self)), @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
50+
return [tableView dequeueReusableHeaderFooterViewWithIdentifier:reuseIdentifier];
6151
}
6252

6353
+ (instancetype)bm_tableViewHeaderFooterViewFromAllocWithTableView:(UITableView *)tableView {
6454
NSString *selfClassName = NSStringFromClass(self.class);
65-
NSString *reuseIdentifier = [selfClassName stringByAppendingString:@"BMDynamicLayoutReuseIdentifier"];
66-
UITableViewHeaderFooterView *headerFooterView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:reuseIdentifier];
67-
if (headerFooterView) {
68-
return headerFooterView;
55+
NSString *reuseIdentifier = [selfClassName stringByAppendingString:@"BMAllocDynamicLayoutReuseIdentifier"];
56+
if ([objc_getAssociatedObject(tableView, (__bridge const void * _Nonnull)(self)) boolValue]) {
57+
// 已注册
58+
return [tableView dequeueReusableHeaderFooterViewWithIdentifier:reuseIdentifier];
6959
}
70-
return [[self alloc] initWithReuseIdentifier:reuseIdentifier];
60+
BM_UITableView_DynamicLayout_LOG(@"✅✅✅✅%@ registerClass", self);
61+
// 未注册,开始注册
62+
[tableView registerClass:self forHeaderFooterViewReuseIdentifier:reuseIdentifier];
63+
objc_setAssociatedObject(tableView, (__bridge const void * _Nonnull)(self), @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
64+
return [tableView dequeueReusableHeaderFooterViewWithIdentifier:reuseIdentifier];
7165
}
7266

7367
@end

0 commit comments

Comments
 (0)