Note that there are some explanatory texts on larger screens.

plurals
  1. POUICollectionView Header Compatible Views
    primarykey
    data
    text
    <p>I've constructed an <code>UICollectionView</code> in a storyboard and implemented all of its required data source and delegate methods in the view controller. In the storyboard, I checked the <code>Section Header</code> property on the collection view and set the header view's class to a subclass of <code>UICollectionResusableView</code> (in the storyboard).</p> <p>From here, I dragged in two UI elements onto the header view via the storyboard--a label and a segmented control:</p> <p><img src="https://i.stack.imgur.com/6fTAo.jpg" alt="enter image description here"></p> <p>When the program is executed, the label appears in the header view of the collection view (with no actual code required), but the segmented control does not. However, when a segmented control is dragged onto a typical <code>UIView</code>, it displays and is manipulatable with no code required. Even when instantiated through code in an <code>IBOutlet</code>, the segmented control does not appear.</p> <p>Why is the segmented control not visible on the collection view's header while it is in a typical <code>UIView</code>, and why does the label display without issue?</p> <p><strong>UPDATE</strong></p> <p>Here is the init method for the custom header view, in which I attempted adding the segmented control programmatically (as opposed to in the storyboard):</p> <pre><code>- (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { _segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"One", @"Two", nil]]; [_segmentedControl setFrame:CGRectMake(0, 0, 100, 50)]; [_segmentedControl addTarget:self action:@selector(segmentedControlChanged:) forControlEvents:UIControlEventValueChanged]; [self addSubview:_segmentedControl]; } return self; } </code></pre> <p>As requested, here is the <code>-[UICollectionReusableView viewForSupplementaryElementOfKind:]</code> method in the main view controller:</p> <pre><code>- (UICollectionReusableView *)collectionView:(UICollectionView *)cv viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { GalleryHeader *headerView = [cv dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath]; return headerView; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload