gpt4 book ai didi

ios - UICollectionView重新加载数据问题

转载 作者:行者123 更新时间:2023-11-29 03:04:58 25 4
gpt4 key购买 nike

我不知道发生了什么,但我的 UICollectionView 没有自动从另一个类重新加载。

我的 UICollectionView 在 class1 中,我通过从 class2 调用 newArray 来更新其中的数据

    class1:

In view DidLoad

UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init];
[aFlowLayout setItemSize:CGSizeMake(self.view.frame.size.width/2 - 15, self.view.frame.size.height/3 - 30)];
[aFlowLayout setSectionInset:UIEdgeInsetsMake(10,10,10,10)];
[aFlowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];

self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:aFlowLayout];

[self.collectionView registerClass:[searchedPersonsCell class] forCellWithReuseIdentifier:@"SongCell"];
[self.collectionView setBackgroundColor:[UIColor clearColor]];
self.collectionView.delegate = self;
self.collectionView.dataSource=self;

self.collectionView.scrollEnabled=YES;
self.collectionView.alwaysBounceVertical=YES;
[self.view addSubview:self.collectionView];

[self.collectionView performSelector:@selector(reloadData) withObject:nil afterDelay:0];

-(void) reloadPersonsData:(NSMutableArray*)newArray
{
NSLog(@"success");
self.personsArray =newArray;
dispatch_async(dispatch_get_main_queue(), ^{
[self.collectionView reloadData];
[self.collectionView performSelector:@selector(reloadData) withObject:nil afterDelay:0];
[self.collectionView setNeedsDisplay];
[self.collectionView setNeedsLayout];

[CATransaction flush];
// [NSTimer scheduledTimerWithTimeInterval:0.3 target:self.collectionView selector:@selector(reload) userInfo:nil repeats:NO];

//tried all the above
});
}

当用户要求更多人时,我通过协议(protocol)访问 class2,

现在在第 2 课:

我正在获取新数组,将其传递给 class1 中的属性数组(它已成功传递,并且我从调试中检查),然后从 class2 调用 reloadPersonsData 函数到 class1(打印 nslog“成功”,因此它正在访问方法。但什么也没有发生!! numberOfItemsInSection 或 numberOfsection 未调用!!并且 uicollectionview 未更新

奇怪的是,如果我从按钮调用 class1 内的相同方法 reloadPersonsData,我就会更新 UiCollectionView!那么这里出了什么问题?为什么从另一个类调用它时没有重新加载谁能帮帮我?

谢谢

最佳答案

只检查class2从class1拥有的实例是否与class1相同

祝你好运

关于ios - UICollectionView重新加载数据问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22881790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com