Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p>Have all the cells you need available in your table view controller. </p></li> <li><p>In your table view's datasource methods (i.e. <code>numberOfSections</code>, <code>numberOfRowsInSection</code>, <code>cellForRowAtIndexPath</code>) you can set all the correct numbers and data for the two states. </p></li> <li><p>When the segmented control changes, you can do two things. Either you simply <code>reloadData</code>, as was suggested before, but then you do not get any animations. Or you use <code>insertRowsAtIndexPaths:withRowAnimation:</code> and <code>deleteRowsAtIndexPaths:withRowAnimation:</code> to get the animation effect.</p></li> </ol> <p>E.g. showing sections 1-2 in case 1 and sections 3-6 in case 2 (section 0 being the top section); each section has 2 rows</p> <pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return _control.selectedSegmentIndex == 0 ? 3 : 4; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return section == 0 ? 1 : 2; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // .. the usual boilerplate if (_control.selectedSegmentIndex == 0) { /* configure cell */ } else { /*do the same for the other case */ } return cell; } -(void)segmentedControlDidChange:(UISegmentedControl*)sender { NSIndexSet *indexes; [_tableView beginUpdates]; if (sender.selectedSegmentIndex == 0) { indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1,4)]; [_tableView deleteSections:indexes withRowAnimation: UITableViewRowAnimationFade]; indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1,2)]; [_tableView insertSections:indexes withRowAnimation: UITableViewRowAnimationFade]; [_tableView reloadSections:indexes withRowAnimation: UITableViewRowAnimationNone]; } else { // do the reverse } [_tableView endUpdates]; } </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.
    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