繁体   English   中英

UICollectionView reloadData问题

[英]UICollectionView reloadData issue

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

我在class1中有我的UICollectionView,并且正在通过从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
    });
}

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

现在在课堂2:

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

奇怪的是,如果我从一个按钮调用了class1内部的相同方法reloadPersonsData,我的UiCollectionView就会更新!!! 那么这是怎么回事?为什么从另一个类中调用它时却没有重新加载它,有人可以帮助我吗?

谢谢

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

祝好运

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM