Question

I posted this question yesterday: https://stackoverflow.com/questions/23119494/what-is-the-best-way-to-dynamically-change-the-style-of-a-uicollectionview and received 0 responses.

I decided to experiment a bit. What I'm trying to do is have a grid style default collection view display change to a single file display when a UISegmentedControl is clicked.

Grid style as default:

enter image description here

After tapping button left segment a single item view is displayed:

enter image description here

I have a method ready that responds to the tap of each segment. I now hide the collectionView when the segment control is tapped and unhide it when it is tapped again.:

- (void)displayTypeSegmentSelected
{
    _selectedDisplayTypeIndex = [_displayTypeControl selectedSegmentIndex];

    if (_selectedDisplayTypeIndex == 0) {
        NSLog(@"Single file item view selected");
        [_collectionView setHidden:YES];
    } else {
        NSLog(@"Grid style view selected");
        [_collectionView setHidden:NO];
    }
}

This works perfectly to show and hide my default collectionView and the functionality of the rest of this controller isn't affected.

Possible solutions:

Now I was wondering if there is a way to create another collectionView with the single file design and have it display whenever the default collectionView is hidden. It will use the exact same datasource and sort of plug in to the controller and just work.

Can this be done view interface builder? If so how do I do this?

Can this be done programmatically? If so how do I go about doing this?

I was wonder if I should have both collectionViews created initially rather than the default at the start and the single file only when segmentControl is clicked.

Would appreciate some examples or clear explanation. Been researching all day with no luck on how to do this.

Regards

Was it helpful?

Solution

It is possible with two view controllers and toggle their position on the navigation stack.

However, for this special case I'd suggest using one view controller with two full-sized views and toggle their position within the view hierarchy of your topmost view or just hide and unhide the one on the top.

OTHER TIPS

You can use the same collection view but only change the data source and delegate.

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