Fix: 尝试修复线上 crash 问题
This commit is contained in:
@@ -955,23 +955,40 @@
|
||||
}
|
||||
|
||||
- (void)updateSelectionForItemAtIndex:(NSInteger)index {
|
||||
// 更新 类型card 的选中状态
|
||||
for (ShoppingMallCategoryCard *view in self.categoryCardArray) {
|
||||
view.isSelected = (view.tag == index);
|
||||
}
|
||||
|
||||
// 移除选中的装扮
|
||||
self.selectedIndexPath = nil;
|
||||
if (self.returnSelectedModel) {
|
||||
self.returnSelectedModel(nil);
|
||||
}
|
||||
|
||||
// 我的装扮页逻辑,若有使用中的装扮,选中。否则选中“未使用”
|
||||
for (UICollectionView *itemView in self.itemCollectionViewArray) {
|
||||
[itemView reloadData];
|
||||
NSInteger selectedIndex = 0;
|
||||
for (MyDressingDataModel *model in [self.myDressingDataCache objectForKey:@(index)]) {
|
||||
if (model.used) {
|
||||
selectedIndex = [[self.myDressingDataCache objectForKey:@(index)] indexOfObject:model]+1;
|
||||
break;
|
||||
NSArray *items = [self.myDressingDataCache objectForKey:@(index)];
|
||||
if (items.count > 0) {
|
||||
NSInteger selectedIndex = 0;
|
||||
for (MyDressingDataModel *model in items) {
|
||||
if (model.used) {
|
||||
selectedIndex = [items indexOfObject:model]+1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 确保 selectedIndex 在合法范围内
|
||||
selectedIndex = MIN(selectedIndex, MAX(0, items.count - 1));
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (selectedIndex < [itemView numberOfItemsInSection:0]) {
|
||||
[itemView selectItemAtIndexPath:[NSIndexPath indexPathForRow:selectedIndex inSection:0]
|
||||
animated:NO
|
||||
scrollPosition:UICollectionViewScrollPositionNone];
|
||||
}
|
||||
});
|
||||
}
|
||||
[itemView selectItemAtIndexPath:[NSIndexPath indexPathForRow:selectedIndex inSection:0] animated:NO scrollPosition:UICollectionViewScrollPositionNone];
|
||||
|
||||
if (self.returnSelectedModel) {
|
||||
NSArray *data = self.dataCache[@(itemView.tag)];
|
||||
self.returnSelectedModel(data.firstObject);
|
||||
@@ -981,11 +998,17 @@
|
||||
|
||||
- (void)updateItemCollectionViewWithShoppingMallData:(NSArray <DressUpShopModel *>*)data
|
||||
atIndex:(NSInteger)index {
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
self.dataCache[@(index)] = data;
|
||||
if (index < self.itemCollectionViewArray.count) {
|
||||
UICollectionView *itemView = self.itemCollectionViewArray[index];
|
||||
[itemView reloadData];
|
||||
[itemView selectItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UICollectionViewScrollPositionNone];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if ([itemView numberOfItemsInSection:0] > 0) {
|
||||
[itemView selectItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UICollectionViewScrollPositionNone];
|
||||
}
|
||||
});
|
||||
if (self.returnSelectedModel) {
|
||||
self.returnSelectedModel(data.firstObject);
|
||||
}
|
||||
@@ -1048,18 +1071,15 @@
|
||||
|
||||
- (void)updateSelectedItem:(NSIndexPath *)indexPath {
|
||||
UICollectionView *itemView = [self.itemCollectionViewArray xpSafeObjectAtIndex:self.currengCategoryIndex];
|
||||
if (itemView) {
|
||||
[itemView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
|
||||
if (itemView && indexPath) {
|
||||
if (indexPath.row < [itemView numberOfItemsInSection:indexPath.section]) {
|
||||
[itemView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
|
||||
}
|
||||
}
|
||||
|
||||
[self refreshCurrentPageData];
|
||||
}
|
||||
|
||||
- (void)refreshCurrentPageData {
|
||||
UICollectionView *itemView = [self.itemCollectionViewArray xpSafeObjectAtIndex:self.currengCategoryIndex];
|
||||
if (itemView) {
|
||||
[self handlePullToRefresh:itemView.refreshControl];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -216,9 +216,14 @@
|
||||
self.tagDataSource = temp;
|
||||
|
||||
[self.collectionView reloadData];
|
||||
[self.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:self.defaultIndex inSection:0]
|
||||
animated:NO
|
||||
scrollPosition:UICollectionViewScrollPositionNone];
|
||||
@kWeakify(self);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
@kStrongify(self);
|
||||
[self.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:self.defaultIndex inSection:0]
|
||||
animated:NO
|
||||
scrollPosition:UICollectionViewScrollPositionNone];
|
||||
});
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@@ -197,8 +197,12 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
|
||||
}
|
||||
|
||||
- (void)setTabArray:(NSArray<PIHomeCategoryTitleModel *> *)tabArray {
|
||||
_tabArray = tabArray;
|
||||
if (46 * _tabArray.count + 12 * (_tabArray.count-1) > KScreenWidth-30) {
|
||||
if (tabArray == nil) {
|
||||
tabArray = @[];
|
||||
}
|
||||
self.tabArray = tabArray;
|
||||
// 如果 tab items 总长度到达或超过边缘,要显示箭头按钮
|
||||
if (46 * self.tabArray.count + 12 * (self.tabArray.count-1) > KScreenWidth-30) {
|
||||
self.gradientMask.hidden = NO;
|
||||
self.arrowButton.hidden = NO;
|
||||
} else {
|
||||
@@ -206,25 +210,33 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
|
||||
self.arrowButton.hidden = YES;
|
||||
}
|
||||
[self.tabCollectionView reloadData];
|
||||
if (_tabArray.count > 0) {
|
||||
if (self.lastSelectedIndex > -1 && self.lastSelectedIndex < self.tabArray.count - 1) {
|
||||
[self.tabCollectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:self.lastSelectedIndex inSection:0]
|
||||
animated:NO
|
||||
scrollPosition:UICollectionViewScrollPositionNone];
|
||||
} else {
|
||||
[self.tabCollectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
|
||||
animated:NO
|
||||
scrollPosition:UICollectionViewScrollPositionNone];
|
||||
|
||||
if (isMSRTL()) {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self.tabCollectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
|
||||
atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
|
||||
animated:YES];
|
||||
});
|
||||
@kWeakify(self);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
@kStrongify(self);
|
||||
if (!self) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.tabArray.count > 0) {
|
||||
if (self.lastSelectedIndex > -1 && self.lastSelectedIndex < self.tabArray.count - 1) {
|
||||
[self.tabCollectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:self.lastSelectedIndex inSection:0]
|
||||
animated:NO
|
||||
scrollPosition:UICollectionViewScrollPositionNone];
|
||||
} else {
|
||||
[self.tabCollectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
|
||||
animated:NO
|
||||
scrollPosition:UICollectionViewScrollPositionNone];
|
||||
|
||||
if (isMSRTL()) {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self.tabCollectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
|
||||
atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
|
||||
animated:YES];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)closeArrow {
|
||||
@@ -232,7 +244,11 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
|
||||
}
|
||||
|
||||
- (void)updateIndex:(NSInteger)index {
|
||||
[self.tabCollectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionNone];
|
||||
if (index < self.tabArray.count) {
|
||||
[self.tabCollectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]
|
||||
animated:YES
|
||||
scrollPosition:UICollectionViewScrollPositionNone];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
@@ -488,9 +488,14 @@
|
||||
row = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
[card.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0] animated:NO scrollPosition:UICollectionViewScrollPositionNone];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (row < dataSource.count) {
|
||||
[card.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0]
|
||||
animated:NO
|
||||
scrollPosition:UICollectionViewScrollPositionNone];
|
||||
}
|
||||
});
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
@@ -628,7 +633,9 @@
|
||||
|
||||
- (void)manualSelectedCell {
|
||||
__block NSInteger row = 0;
|
||||
@kWeakify(self);
|
||||
[self.skins enumerateObjectsUsingBlock:^(RoomMicInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
@kStrongify(self);
|
||||
if ([obj.id isEqualToString:@(self.usedID).stringValue]) {
|
||||
row = idx;
|
||||
*stop = YES;
|
||||
@@ -745,7 +752,9 @@
|
||||
|
||||
- (void)manualSelectedCell {
|
||||
__block NSInteger row = 0;
|
||||
@kWeakify(self);
|
||||
[self.effects enumerateObjectsUsingBlock:^(RoomMicInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
@kStrongify(self);
|
||||
if ([obj.id isEqualToString:@(self.usedID).stringValue]) {
|
||||
row = idx;
|
||||
*stop = YES;
|
||||
|
Reference in New Issue
Block a user