Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions SDAutoLayoutDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@
TargetAttributes = {
487D3EB01BCB9EC700A66173 = {
CreatedOnToolsVersion = 6.4;
DevelopmentTeam = 8D5EHT9KTL;
DevelopmentTeam = JZ4N33QRV7;
};
487D3EC91BCB9EC700A66173 = {
CreatedOnToolsVersion = 6.4;
Expand Down Expand Up @@ -2039,9 +2039,9 @@
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = 8D5EHT9KTL;
DEVELOPMENT_TEAM = JZ4N33QRV7;
INFOPLIST_FILE = SDAutoLayoutDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.gsdiosnew.test;
PRODUCT_NAME = SDAutoLayoutDemo;
Expand All @@ -2056,9 +2056,9 @@
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = 8D5EHT9KTL;
DEVELOPMENT_TEAM = JZ4N33QRV7;
INFOPLIST_FILE = SDAutoLayoutDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.gsdiosnew.test;
PRODUCT_NAME = SDAutoLayoutDemo;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>SDAutoLayoutDemo.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ typedef void (^AutoCellHeightDataSettingBlock)(UITableViewCell *cell);
*/
- (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath model:(id)model keyPath:(NSString *)keyPath cellClass:(Class)cellClass contentViewWidth:(CGFloat)contentViewWidth;

/*
如果使用自定义的reuseIdentifier在cell中进行了业务判断处理,必须使用该方法
*/
-(CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath model:(id)model keyPath:(NSString *)keyPath cellClass:(Class)cellClass contentViewWidth:(CGFloat)contentViewWidth reuseIdentifier:(NSString*)reuseIdentifier;

/**
* 返回计算出的cell高度(普通简化版方法,同样只需一步设置即可完成)(用法:见DemoVC14)
* cellClass : 当前的indexPath对应的cell的class
Expand All @@ -64,6 +69,11 @@ typedef void (^AutoCellHeightDataSettingBlock)(UITableViewCell *cell);
*/
- (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath cellClass:(Class)cellClass cellContentViewWidth:(CGFloat)width cellDataSetting:(AutoCellHeightDataSettingBlock)cellDataSetting;

/*
如果使用自定义的reuseIdentifier在cell中进行了业务判断处理,必须使用该方法
*/
- (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath cellClass:(Class)cellClass cellContentViewWidth:(CGFloat)width cellDataSetting:(AutoCellHeightDataSettingBlock)cellDataSetting reuseIdentifier:(NSString*)reuseIdentifier;

/** 刷新tableView但不清空之前已经计算好的高度缓存,用于直接将新数据拼接在旧数据之后的tableView刷新 */
- (void)reloadDataWithExistedHeightCache;

Expand Down Expand Up @@ -159,6 +169,8 @@ typedef void (^AutoCellHeightDataSettingBlock)(UITableViewCell *cell);

- (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath model:(id)model keyPath:(NSString *)keyPath cellClass:(Class)cellClass;

-(CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath model:(id)model keyPath:(NSString *)keyPath cellClass:(Class)cellClass contentViewWidth:(CGFloat)contentViewWidth reuseIdentifier:(NSString*)reuseIdentifier;


- (NSMutableArray *)subviewFrameCachesWithIndexPath:(NSIndexPath *)indexPath;;
- (void)setSubviewFrameCache:(CGRect)rect WithIndexPath:(NSIndexPath *)indexPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,20 @@ - (void)setup

- (void)registerCellWithCellClass:(Class)cellClass
{
[_modelTableview registerClass:cellClass forCellReuseIdentifier:NSStringFromClass(cellClass)];
self.modelCell = [_modelTableview dequeueReusableCellWithIdentifier:NSStringFromClass(cellClass)];
[self registerCellWithCellClass:cellClass reuseIdentifier:NSStringFromClass(cellClass)];
}

- (void)registerCellWithCellClass:(Class)cellClass reuseIdentifier:(NSString*)reuseIdentifier
{
[_modelTableview registerClass:cellClass forCellReuseIdentifier:reuseIdentifier];
self.modelCell = [_modelTableview dequeueReusableCellWithIdentifier:reuseIdentifier];

if (!self.modelCell.contentView.subviews.count) {
NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@.nib", NSStringFromClass(cellClass)] ofType:nil];
if (path) {
self.modelCell = nil;
[_modelTableview registerNib:[UINib nibWithNibName:NSStringFromClass(cellClass) bundle:nil] forCellReuseIdentifier:NSStringFromClass(cellClass)];
self.modelCell = [_modelTableview dequeueReusableCellWithIdentifier:NSStringFromClass(cellClass)];
[_modelTableview registerNib:[UINib nibWithNibName:NSStringFromClass(cellClass) bundle:nil] forCellReuseIdentifier:reuseIdentifier];
self.modelCell = [_modelTableview dequeueReusableCellWithIdentifier:reuseIdentifier];
}
}
if (self.modelCell) {
Expand Down Expand Up @@ -302,12 +307,17 @@ - (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath model:(id)model keyPa
}

- (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath model:(id)model keyPath:(NSString *)keyPath cellClass:(Class)cellClass
{
return [self cellHeightForIndexPath:indexPath model:model keyPath:keyPath cellClass:cellClass reuseIdentifier:NSStringFromClass(cellClass)];
}

- (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath model:(id)model keyPath:(NSString *)keyPath cellClass:(Class)cellClass reuseIdentifier:(NSString*)reuseIdentifier
{
if (![self.modelCell isKindOfClass:cellClass]) {
self.modelCell = nil;
self.modelCell = [_modelCellsDict objectForKey:NSStringFromClass(cellClass)];
if (!self.modelCell) {
[self registerCellWithCellClass:cellClass];
[self registerCellWithCellClass:cellClass reuseIdentifier:reuseIdentifier];
}
_modelCell.contentView.tag = kSDModelCellTag;
}
Expand All @@ -317,6 +327,7 @@ - (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath model:(id)model keyPa
return [self cellHeightForIndexPath:indexPath model:model keyPath:keyPath];
}


- (void)setContentViewWidth:(CGFloat)contentViewWidth
{
if (_contentViewWidth == contentViewWidth) return;
Expand Down Expand Up @@ -418,20 +429,29 @@ - (void)sd_moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath
*/

- (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath model:(id)model keyPath:(NSString *)keyPath cellClass:(Class)cellClass contentViewWidth:(CGFloat)contentViewWidth
{
return [self cellHeightForIndexPath:indexPath model:model keyPath:keyPath cellClass:cellClass contentViewWidth:contentViewWidth reuseIdentifier:NSStringFromClass(cellClass)];
}

- (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath model:(id)model keyPath:(NSString *)keyPath cellClass:(Class)cellClass contentViewWidth:(CGFloat)contentViewWidth reuseIdentifier:(NSString*)reuseIdentifier
{
self.cellAutoHeightManager.modelTableview = self;

self.cellAutoHeightManager.contentViewWidth = contentViewWidth;

return [self.cellAutoHeightManager cellHeightForIndexPath:indexPath model:model keyPath:keyPath cellClass:cellClass];
return [self.cellAutoHeightManager cellHeightForIndexPath:indexPath model:model keyPath:keyPath cellClass:cellClass reuseIdentifier:reuseIdentifier];
}

- (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath cellClass:(__unsafe_unretained Class)cellClass cellContentViewWidth:(CGFloat)width cellDataSetting:(AutoCellHeightDataSettingBlock)cellDataSetting
{
return [self cellHeightForIndexPath:indexPath model:nil keyPath:nil cellClass:cellClass contentViewWidth:width reuseIdentifier:NSStringFromClass(cellClass)];
}

- (CGFloat)cellHeightForIndexPath:(NSIndexPath *)indexPath cellClass:(Class)cellClass cellContentViewWidth:(CGFloat)width cellDataSetting:(AutoCellHeightDataSettingBlock)cellDataSetting reuseIdentifier:(NSString*)reuseIdentifier
{
self.cellDataSetting = cellDataSetting;

return [self cellHeightForIndexPath:indexPath model:nil keyPath:nil cellClass:cellClass contentViewWidth:width];
return [self cellHeightForIndexPath:indexPath model:nil keyPath:nil cellClass:cellClass contentViewWidth:width reuseIdentifier:reuseIdentifier];
}

- (void)reloadDataWithExistedHeightCache
Expand Down