Question

I don't know what is happening, but my UICollectionView is not reloading from another class automatically.

I have my UICollectionView in class1 and i am updating the data in it by calling a newArray from class2

    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
    });
}

when user ask for more persons, i access class2 by a protocol,

Now In Class 2:

I am Getting the new Array, passing it to the property array in class1(it is passed successfully and i checked from debug) then calling reloadPersonsData Function from class2 to class1(the nslog "success" is printed so it is accessing the method. But Nothing is happened!! numberOfItemsInSection or numberOfsection are not called!!and the uicollectionview is not updated

The weird thing, if i called the same method reloadPersonsData inside class1 from a button , i got the UiCollectionView updated!!! so what is wrong here?why it is not reloaded when calling it from another class can anyone help me?

Thank you

Was it helpful?

Solution

Just Check if the instance that class2 owned from class1 is the same as class1

Good Luck

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top