diff --git a/SDAutoLayoutDemo.xcodeproj/project.pbxproj b/SDAutoLayoutDemo.xcodeproj/project.pbxproj index da5e17e..17a1986 100644 --- a/SDAutoLayoutDemo.xcodeproj/project.pbxproj +++ b/SDAutoLayoutDemo.xcodeproj/project.pbxproj @@ -1651,7 +1651,7 @@ TargetAttributes = { 487D3EB01BCB9EC700A66173 = { CreatedOnToolsVersion = 6.4; - DevelopmentTeam = 8D5EHT9KTL; + DevelopmentTeam = JZ4N33QRV7; }; 487D3EC91BCB9EC700A66173 = { CreatedOnToolsVersion = 6.4; @@ -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; @@ -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; diff --git a/SDAutoLayoutDemo.xcodeproj/project.xcworkspace/xcuserdata/jsbios.xcuserdatad/UserInterfaceState.xcuserstate b/SDAutoLayoutDemo.xcodeproj/project.xcworkspace/xcuserdata/jsbios.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..a71fbba Binary files /dev/null and b/SDAutoLayoutDemo.xcodeproj/project.xcworkspace/xcuserdata/jsbios.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/SDAutoLayoutDemo.xcodeproj/xcuserdata/jsbios.xcuserdatad/xcschemes/xcschememanagement.plist b/SDAutoLayoutDemo.xcodeproj/xcuserdata/jsbios.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..057c505 --- /dev/null +++ b/SDAutoLayoutDemo.xcodeproj/xcuserdata/jsbios.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + SDAutoLayoutDemo.xcscheme + + orderHint + 0 + + + + diff --git a/SDAutoLayoutDemo/SDAutoLayout/UITableView+SDAutoTableViewCellHeight.h b/SDAutoLayoutDemo/SDAutoLayout/UITableView+SDAutoTableViewCellHeight.h index 84ff4ff..5a06d84 100644 --- a/SDAutoLayoutDemo/SDAutoLayout/UITableView+SDAutoTableViewCellHeight.h +++ b/SDAutoLayoutDemo/SDAutoLayout/UITableView+SDAutoTableViewCellHeight.h @@ -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 @@ -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; @@ -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; diff --git a/SDAutoLayoutDemo/SDAutoLayout/UITableView+SDAutoTableViewCellHeight.m b/SDAutoLayoutDemo/SDAutoLayout/UITableView+SDAutoTableViewCellHeight.m index 63f800d..89762d0 100644 --- a/SDAutoLayoutDemo/SDAutoLayout/UITableView+SDAutoTableViewCellHeight.m +++ b/SDAutoLayoutDemo/SDAutoLayout/UITableView+SDAutoTableViewCellHeight.m @@ -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) { @@ -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; } @@ -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; @@ -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