Reputation: 1865
I am trying to implement a "profile" page in my app which is similar to Instagram profile page
But the problem I have is the Cell from UICollectionView below get loaded by -collectionView:cellForItemAtIndexPath But it load every cells at once ,it does not just load the visible cell as it should. And this is because it is inside scroll view ,the make every cell loads immediately.
The image for cell will be sent from server via API and I want to do a loading when user scroll to 2/3 of page. And this can be done easily in UICollectionViewController.But I want to know how to do that in ViewController that contain collectionView in lower path.
Please help. I think using Header of CollectionView as an upper part of page might solve the problem. But I also want to implement that when user tap the button and then the display below change ( just like instagram page). So I am not sure what direction should I go . Should it be a custom container VC or something else ?
TIA
Upvotes: 2
Views: 1177
Reputation: 62686
UICollectionView is very versatile. It can handle the entire view, including the upper part that pertains to the user's profile.The trick is to make use of a "supplementary view" in collection view terms (like a header view in table view terms).
I suggest that you throw away the scroll view and make the collection view do all the work for you. Just like you register classes for cells, register a view for the user profile portion of your UI using:
- (void)registerClass:(Class)viewClass forSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier
And respond to the datasource method:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
By answering the that user profile view.
Upvotes: 1