iOS: do not use itemCount in list,use rowCount instead

This commit is contained in:
pengfei.zhou 2022-07-15 13:52:39 +08:00 committed by osborn
parent 6512841f82
commit 99cee47134

View File

@ -208,8 +208,8 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
} }
- (void)callLoadMore { - (void)callLoadMore {
if (self.itemCount != self.loadAnchor) { if (self.rowCount - 1 != self.loadAnchor) {
self.loadAnchor = self.itemCount; self.loadAnchor = self.rowCount - 1;
[self callJSResponse:self.onLoadMoreFuncId, nil]; [self callJSResponse:self.onLoadMoreFuncId, nil];
} }
} }
@ -221,7 +221,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
NSString *reuseId = props[@"identifier"]; NSString *reuseId = props[@"identifier"];
self.itemActions[@(position)] = props[@"actions"]; self.itemActions[@(position)] = props[@"actions"];
if (self.loadMore if (self.loadMore
&& position >= self.itemCount && position >= self.rowCount - 1
&& self.onLoadMoreFuncId) { && self.onLoadMoreFuncId) {
reuseId = @"doricLoadMoreCell"; reuseId = @"doricLoadMoreCell";
[self callLoadMore]; [self callLoadMore];
@ -311,7 +311,7 @@ - (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView tra
} }
- (NSDictionary *)itemModelAt:(NSUInteger)position { - (NSDictionary *)itemModelAt:(NSUInteger)position {
if (self.loadMore && position >= self.itemCount) { if (self.loadMore && position >= self.rowCount - 1) {
if (self.loadMoreViewId && self.loadMoreViewId.length > 0) { if (self.loadMoreViewId && self.loadMoreViewId.length > 0) {
return [self subModelOf:self.loadMoreViewId]; return [self subModelOf:self.loadMoreViewId];
} else { } else {
@ -349,7 +349,7 @@ - (NSDictionary *)itemModelAt:(NSUInteger)position {
- (void)blendSubNode:(NSDictionary *)subModel { - (void)blendSubNode:(NSDictionary *)subModel {
///Here async blend sub node because the item count need to be applied first. ///Here async blend sub node because the item count need to be applied first.
NSUInteger currentCount = self.itemCount + (self.loadMore ? 1 : 0); NSUInteger currentCount = self.rowCount;
NSString *viewId = subModel[@"id"]; NSString *viewId = subModel[@"id"];
DoricViewNode *viewNode = [self subNodeWithViewId:viewId]; DoricViewNode *viewNode = [self subNodeWithViewId:viewId];
BOOL skipReload = NO; BOOL skipReload = NO;
@ -517,7 +517,7 @@ - (void)scrollToItem:(NSDictionary *)params {
BOOL animated = [params[@"animated"] boolValue]; BOOL animated = [params[@"animated"] boolValue];
NSUInteger scrolledPosition = [params[@"index"] unsignedIntegerValue]; NSUInteger scrolledPosition = [params[@"index"] unsignedIntegerValue];
if (scrolledPosition < self.itemCount && scrolledPosition >= 0) { if (scrolledPosition < self.rowCount && scrolledPosition >= 0) {
for (int i = 0; i <= scrolledPosition; i++) { for (int i = 0; i <= scrolledPosition; i++) {
[self tableView:self.view cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]; [self tableView:self.view cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
} }