I have two UICollectionViews
in my UIViewController
.
Let's say they are A and B, A and B are positioned at the same place in UIViewcontroller in the nib file, they have exact same sizes.
Now I set
A.delegate = self;
A.dataSource = self;
B.delegate = self;
B.dataSource = self;
[A registerNib:nib forCellWithReuseIdentifier:CELL_A];
[B registerNib:nib forCellWithReuseIdentifier:CELL_B];
in ViewDidLoad
then in CellForItemAtIndexPath
,
I use a switch statement to show different cells.
then I use a segment control to control displaying a correct UICollectionViewcontroller
on my selected segment.
In segment control value changed code. I use:
- (IBAction)sectionSelected:(id)sender {
if (choosing A) {
B.hidden = YES;
A.hidden = NO;
A.backgroundColor = [UIColor blackColor];
[self getAData];
[A reloadData];
}
else if (choosing B) {
A.hidden = YES;
B.hidden = NO;
B.backgroundColor = [UIColor orangeColor];
[self getBData];
[B reloadData];
}
}
A is displayed correctly when I set default selected segment as A. but when I switch to B, I can see B is load but the data is not loaded to B so I couldn't see anything except for the orange background. I put the NSLog in CellForItemAtIndexPath
and find that the method is not being called after reloadData
.
Here is some logging I get for A.collectionViewLayout.collectionViewContentSize;
and B.collectionViewLayout.collectionViewContentSize;
content size of B = 768.000000, 24.000000
content size of A = 768.000000, 880.000000
When I set default selected segment as B, B is displayed correctly. I switch back to A which is also displayed correctly. However when I switch back to B again it shows an empty orange screen. Any idea what have gone wrong with my code?