我不知道发生了什么,但是我的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
});
}当用户要求更多的人时,我通过协议访问class2,
现在在第二班:
我正在获取新的数组,将其传递到class1中的属性数组(成功传递并从调试中检查),然后将reloadPersonsData函数从class2调用到class1( nslog "success“被打印出来,因此它正在访问该方法。但什么都没发生!!不调用numberOfItemsInSection或numberOfsection!并且未更新uicollectionview。
奇怪的是,如果我从一个按钮调用相同的方法reloadPersonsData在class1中,我得到了UiCollectionView更新!那么,这里有什么问题呢?为什么在从另一个类调用它时没有重新加载它,有人能帮我吗?
谢谢
发布于 2014-04-05 15:12:09
只需检查class2从class1拥有的实例是否与class1相同
祝好运
https://stackoverflow.com/questions/22881790
复制相似问题