Skip to content

Commit

Permalink
修复获取对应ZHTableViewCell索引错误
Browse files Browse the repository at this point in the history
  • Loading branch information
josercc committed Feb 28, 2020
1 parent 73a76d5 commit 0648eb8
Show file tree
Hide file tree
Showing 26 changed files with 47 additions and 30 deletions.
22 changes: 0 additions & 22 deletions ZHTableViewGroupExample/ZHTableViewGroupObjc/Info.plist

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ typedef CGFloat (^ZHTableViewDataSourceCustomHeightCompletionHandle)(ZHTableView
- (void)reloadCellWithGroupIndex:(NSUInteger)groupIndex
cellIndex:(NSUInteger)cellIndex;

- (NSMutableArray<NSIndexPath *> *)indexPathsWithTableViewCell:(ZHTableViewCell *)tableViewCell;

@end

@interface ZHTableViewDataSource (ReloadData)
Expand Down Expand Up @@ -258,6 +260,8 @@ typedef CGFloat (^ZHTableViewDataSourceCustomHeightCompletionHandle)(ZHTableView
groupIndex:(NSUInteger)groupIndex
cellIndex:(NSUInteger)cellIndex;

- (void)updatesTableView:(void(^)(void))update;

@end

@interface ZHTableViewDataSource (Cell)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,21 @@ - (void)reloadCellWithTableViewCellConfig:(BOOL (^)(NSUInteger section, NSUInteg
NSIndexPath *indexPath = [self indexPathWithTableViewCell:obj];
[indexPaths addObject:[NSIndexPath indexPathForRow:(indexPath.row + i) inSection:indexPath.section]];
}
[self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
[self updatesTableView:^{
[self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
}];
}];
}

- (NSMutableArray<NSIndexPath *> *)indexPathsWithTableViewCell:(ZHTableViewCell *)tableViewCell {
NSMutableArray<NSIndexPath *> *indexPaths = [NSMutableArray array];
for (NSUInteger i = 0; i < tableViewCell.cellNumber; i++) {
NSIndexPath *indexPath = [self indexPathWithTableViewCell:tableViewCell];
[indexPaths addObject:[NSIndexPath indexPathForRow:(indexPath.row + i) inSection:indexPath.section]];
}
return indexPaths;
}

@end

@implementation ZHTableViewDataSource (ReloadData)
Expand Down Expand Up @@ -568,10 +579,12 @@ - (NSIndexPath *)indexPathWithTableViewCell:(ZHTableViewCell *)tableViewCell {
section = idx;
__block NSUInteger row = 0;
[obj.cells enumerateObjectsUsingBlock:^(ZHTableViewCell * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
row += idx;
if ([tableViewCell isEqual:obj]) {
indexPath = [NSIndexPath indexPathForRow:row inSection:section];
*stop = YES;
return;
}
row += obj.cellNumber;
}];
}];
return indexPath;
Expand All @@ -582,14 +595,19 @@ - (NSIndexPath *)indexPathWithTableViewCell:(ZHTableViewCell *)tableViewCell {
@implementation ZHTableViewDataSource (Hidden)

- (void)reloadAllHiddenCell {
NSMutableArray<NSIndexPath *> *needReloadIndexPath = [NSMutableArray array];
[[self filterCellWithConfig:^BOOL(NSUInteger section, NSUInteger row, ZHTableViewCell *tableViewCell) {
return YES;
}] enumerateObjectsUsingBlock:^(ZHTableViewCell * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (!obj.hiddenBlock) {
return;
}
[self reloadCellWithTableViewCell:obj];
[needReloadIndexPath addObjectsFromArray:[self indexPathsWithTableViewCell:obj]];
}] ;
[self updatesTableView:^{
[self.tableView reloadRowsAtIndexPaths:needReloadIndexPath
withRowAnimation:UITableViewRowAnimationAutomatic];
}];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,8 @@ - (UITableViewCell *)cellForTableViewWithTableView:(UITableView *)tableView inde
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableViewCell.identifier];
NSIndexPath *realIndexPath = [self indexPathWithCell:tableViewCell indexPath:indexPath];
if (tableViewCell.hiddenBlock && tableViewCell.hiddenBlock(realIndexPath)) {
cell.hidden = YES;
} else {
cell.hidden = NO;
}
BOOL isHidden = tableViewCell.hiddenBlock && tableViewCell.hiddenBlock(realIndexPath);
cell.hidden = isHidden;
if (config) {
[self tableViewCell:tableViewCell
configCell:cell
Expand Down
20 changes: 20 additions & 0 deletions ZHTableViewGroupObjc.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Be sure to run `pod lib lint ZHTableViewGroup.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
s.name = 'ZHTableViewGroupObjc'
s.version = '3.5.0-beta-2'
s.summary = 'Manger UITableView DataSource More Cell Style'

s.homepage = 'https://github.com/josercc/ZHTableViewGroup'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { '15038777234' => '[email protected]' }
s.source = { :git => 'https://github.com/josercc/ZHTableViewGroup.git', :tag => s.version.to_s }
s.ios.deployment_target = '8.0'
s.source_files = 'ZHTableViewGroupExample/ZHTableViewGroupObjc/**/*.{h,m}'
end

0 comments on commit 0648eb8

Please sign in to comment.