首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UICollectionView reloadData问题

UICollectionView reloadData问题
EN

Stack Overflow用户
提问于 2014-04-05 13:53:13
回答 1查看 1.2K关注 0票数 0

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

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

代码语言:javascript
复制
    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,

现在在第二班:

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

奇怪的是,如果我从一个按钮调用相同的方法reloadPersonsData在class1中,我得到了UiCollectionView更新!那么,这里有什么问题呢?为什么在从另一个类调用它时没有重新加载它,有人能帮我吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-05 15:12:09

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

祝好运

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22881790

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档