Skip to content

Commit 3cd024b

Browse files
committed
调整 nib 加载。
1 parent 7f057d8 commit 3cd024b

File tree

6 files changed

+18
-28
lines changed

6 files changed

+18
-28
lines changed

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.2'
3+
s.version = '5.1.3'
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/Private/UITableView+BMPrivate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
#import <UIKit/UIKit.h>
2424

25+
// 兼容 Swift
26+
#define kSwiftClassNibName(clasName) ([clasName rangeOfString:@"."].location != NSNotFound ? [clasName componentsSeparatedByString:@"."].lastObject : clasName)
27+
2528
/// 内部使用到的分类。
2629
@interface UITableView (BMPrivate)
2730

UITableViewDynamicLayoutCacheHeight/Classes/UITableView+BMDynamicLayout.m

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#import "UITableViewHeaderFooterView+BMDynamicLayout.h"
2727
#import "UITableViewCell+BMDynamicLayout.h"
2828
#import "UITableViewDynamicLayoutCacheHeight.h"
29+
#import "UITableView+BMPrivate.h"
2930

3031
void tableViewDynamicLayoutLayoutIfNeeded(UIView *view);
3132
inline void tableViewDynamicLayoutLayoutIfNeeded(UIView *view) {
@@ -84,11 +85,7 @@ @implementation UITableView (BMDynamicLayout)
8485

8586
- (UIView *)_cellViewWithCellClass:(Class)clas {
8687
NSString *cellClassName = NSStringFromClass(clas);
87-
// 兼容 Swift
88-
if ([cellClassName rangeOfString:@"."].location != NSNotFound) {
89-
cellClassName = [cellClassName componentsSeparatedByString:@"."].lastObject;
90-
}
91-
88+
9289
NSMutableDictionary *dict = objc_getAssociatedObject(self, _cmd);
9390
if (!dict) {
9491
dict = @{}.mutableCopy;
@@ -101,10 +98,10 @@ - (UIView *)_cellViewWithCellClass:(Class)clas {
10198
}
10299

103100
NSBundle *bundle = [NSBundle bundleForClass:clas];
104-
NSString *path = [bundle pathForResource:cellClassName ofType:@"nib"];
101+
NSString *path = [bundle pathForResource:kSwiftClassNibName(cellClassName) ofType:@"nib"];
105102
UITableViewCell *cell = nil;
106103
if (path.length > 0) {
107-
NSArray <UITableViewCell *> *arr = [[UINib nibWithNibName:cellClassName bundle:bundle] instantiateWithOwner:nil options:nil];
104+
NSArray <UITableViewCell *> *arr = [[UINib nibWithNibName:kSwiftClassNibName(cellClassName) bundle:bundle] instantiateWithOwner:nil options:nil];
108105
for (UITableViewCell *obj in arr) {
109106
if ([obj isMemberOfClass:clas]) {
110107
cell = obj;
@@ -175,11 +172,7 @@ - (CGFloat)_heightWithCellClass:(Class)clas
175172
- (UIView *)_headerFooterViewWithHeaderFooterViewClass:(Class)clas
176173
sel:(SEL)sel {
177174
NSString *headerFooterViewClassName = NSStringFromClass(clas);
178-
// 兼容 Swift
179-
if ([headerFooterViewClassName rangeOfString:@"."].location != NSNotFound) {
180-
headerFooterViewClassName = [headerFooterViewClassName componentsSeparatedByString:@"."].lastObject;
181-
}
182-
175+
183176
NSMutableDictionary *dict = objc_getAssociatedObject(self, sel);
184177
if (!dict) {
185178
dict = @{}.mutableCopy;
@@ -192,10 +185,10 @@ - (UIView *)_headerFooterViewWithHeaderFooterViewClass:(Class)clas
192185
}
193186

194187
NSBundle *bundle = [NSBundle bundleForClass:clas];
195-
NSString *path = [bundle pathForResource:headerFooterViewClassName ofType:@"nib"];
188+
NSString *path = [bundle pathForResource:kSwiftClassNibName(headerFooterViewClassName) ofType:@"nib"];
196189
UIView *headerView = nil;
197190
if (path.length > 0) {
198-
NSArray <UITableViewHeaderFooterView *> *arr = [[UINib nibWithNibName:headerFooterViewClassName bundle:bundle] instantiateWithOwner:nil options:nil];
191+
NSArray <UITableViewHeaderFooterView *> *arr = [[UINib nibWithNibName:kSwiftClassNibName(headerFooterViewClassName) bundle:bundle] instantiateWithOwner:nil options:nil];
199192
for (UITableViewHeaderFooterView *obj in arr) {
200193
if ([obj isMemberOfClass:clas]) {
201194
headerView = obj;

UITableViewDynamicLayoutCacheHeight/Classes/UITableViewCell+BMDynamicLayout.m

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#import "UITableViewCell+BMDynamicLayout.h"
2424
#import <objc/runtime.h>
25+
#import "UITableView+BMPrivate.h"
2526

2627
@implementation UITableViewCell (BMDynamicLayout)
2728

@@ -41,18 +42,14 @@ + (instancetype)bm_tableViewCellFromNibWithTableView:(UITableView *)tableView {
4142
return cell;
4243
}
4344

44-
if ([selfClassName rangeOfString:@"."].location != NSNotFound) {
45-
selfClassName = [selfClassName componentsSeparatedByString:@"."].lastObject;
46-
}
47-
4845
NSBundle *bundle = [NSBundle bundleForClass:self.class];
49-
NSString *path = [bundle pathForResource:selfClassName ofType:@"nib"];
46+
NSString *path = [bundle pathForResource:kSwiftClassNibName(selfClassName) ofType:@"nib"];
5047
if (path.length == 0) {
5148
NSAssert(NO, @"你的 Cell 不是 IB 创建的");
5249
return nil;
5350
}
5451

55-
NSArray <UITableViewCell *> *arr = [[UINib nibWithNibName:selfClassName bundle:bundle] instantiateWithOwner:nil options:nil];
52+
NSArray <UITableViewCell *> *arr = [[UINib nibWithNibName:kSwiftClassNibName(selfClassName) bundle:bundle] instantiateWithOwner:nil options:nil];
5653
for (UITableViewCell *obj in arr) {
5754
if ([obj isMemberOfClass:self.class]) {
5855
cell = obj;

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.2
24+
/// v5.1.3
2525
////////////////
2626

2727
#ifndef UITableViewDynamicLayoutCacheHeight_h

UITableViewDynamicLayoutCacheHeight/Classes/UITableViewHeaderFooterView+BMDynamicLayout.m

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#import "UITableViewHeaderFooterView+BMDynamicLayout.h"
2424
#import <objc/runtime.h>
25+
#import "UITableView+BMPrivate.h"
2526

2627
@implementation UITableViewHeaderFooterView (BMDynamicLayout)
2728

@@ -40,18 +41,14 @@ + (instancetype)bm_tableViewHeaderFooterViewFromNibWithTableView:(UITableView *)
4041
if (headerFooterView) {
4142
return headerFooterView;
4243
}
43-
// 兼容 Swift
44-
if ([selfClassName rangeOfString:@"."].location != NSNotFound) {
45-
selfClassName = [selfClassName componentsSeparatedByString:@"."].lastObject;
46-
}
4744

4845
NSBundle *bundle = [NSBundle bundleForClass:self.class];
49-
NSString *path = [bundle pathForResource:selfClassName ofType:@"nib"];
46+
NSString *path = [bundle pathForResource:kSwiftClassNibName(selfClassName) ofType:@"nib"];
5047
if (path.length == 0) {
5148
NSAssert(NO, @"你的 UITableViewHeaderFooterView 不是 IB 创建的");
5249
return nil;
5350
}
54-
NSArray <UITableViewHeaderFooterView *> *arr = [[UINib nibWithNibName:selfClassName bundle:bundle] instantiateWithOwner:nil options:nil];
51+
NSArray <UITableViewHeaderFooterView *> *arr = [[UINib nibWithNibName:kSwiftClassNibName(selfClassName) bundle:bundle] instantiateWithOwner:nil options:nil];
5552
for (UITableViewHeaderFooterView *obj in arr) {
5653
if ([obj isMemberOfClass:self.class]) {
5754
headerFooterView = obj;

0 commit comments

Comments
 (0)