Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not able to reproduce your storyboard problem, it works just fine for me when i add the segmented control by dragging it directly in the storyboard (with no code required). As for your alternative way of adding it programmatically, the problem here is that when a view is initialized from the storyboard (as it is in this case), the <code>initWithCoder</code> initializer method is used (not the <code>initWithFrame</code> initializer method). Hence, if you override that method, inserting the code in there, it should work:</p> <pre><code>-(id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if(self){ _segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"One", @"Two", nil]]; _segmentedControl.bounds = CGRectMake(0, 0, 100, 50); [_segmentedControl addTarget:self action:@selector(segmentedControlChanged:) forControlEvents:UIControlEventValueChanged]; [self addSubview:_segmentedControl]; } return self; } </code></pre> <p>P.S. It doesnt affect this specific case, but you should just do:</p> <pre><code>GalleryHeader *headerView = [cv dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"HeaderView" forIndexPath:indexPath]; </code></pre> <p>instead of:</p> <pre><code>GalleryHeader *headerView = [cv dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath]; </code></pre> <p>As it is the collection view that will ask for the right kind of view, you should worry about specifying it!</p> <p>EDIT: The steps i followed to create the header from storyboard are:</p> <ul> <li>Select the collection view and tick the box labelled <em>Section Header</em></li> </ul> <p><img src="https://i.stack.imgur.com/XWj77.png" alt=""></p> <ul> <li>Select the newly created header and select the right class in the identity inspector</li> </ul> <p><img src="https://i.stack.imgur.com/ZPOLy.png" alt="enter image description here"></p> <ul> <li>Give the header section a unique identifier</li> </ul> <p><img src="https://i.stack.imgur.com/cqnvq.png" alt="enter image description here"></p> <ul> <li>Drag the UI elements in the header in the storyboard (i also changed its background color)</li> </ul> <p><img src="https://i.stack.imgur.com/XZ9EV.png" alt="enter image description here"></p> <ul> <li>Finally implement the <code>collectionView:viewForSupplementaryElementOfKind:atIndexPath:</code> method in your collection view's data source class</li> </ul> <pre><code> -(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { return [self.collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"collectionViewHeader" forIndexPath:indexPath]; } </code></pre> <p>Let me know if you can spot any difference between what you did and what I did!</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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