Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Write a UIViewController that manages your 2 VC's and transitions between the MKMapView and UITableView in response to the segmented control. First set up the nib for this new VC in Interface Builder: add an UISegementedControl and a simple UIView (contentView). The interface file contains references to the UI Elements and to the 2 VC's + an action to respond to the segmented control:</p> <pre><code>// // MapAndTableViewController.h // #import &lt;UIKit/UIKit.h&gt; #import "MyMapViewController.h" #import "MyTableViewController.h" @interface MapAndTableViewController : UIViewController { IBOutlet UISegmentedControl* segmentedControl; IBOutlet UIView* contentView; UIViewController* firstVC; UIViewController* secondVC; } -(IBAction) valueChanged:(UISegmentedControl*) sender; @end </code></pre> <p>Implementation:</p> <pre><code>// // MapAndTableViewController.m // #import "MapAndTableViewController.h" @implementation MapAndTableViewController -(IBAction) valueChanged:(UISegmentedControl*) sender { if (sender.selectedSegmentIndex == 0) { [UIView transitionFromView:[contentView.subviews lastObject] toView:firstVC.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil]; } if (sender.selectedSegmentIndex == 1) { [UIView transitionFromView:[contentView.subviews lastObject] toView:secondVC.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil]; } } -(void)awakeFromNib { firstVC = [[MyMapViewController alloc] initWithNibName:@"MyMapViewController" bundle:nil]; secondVC = [[MyTableViewController alloc] initWithNibName:@"MyTableViewController" bundle:nil]; } - (void)viewDidLoad { [super viewDidLoad]; [contentView addSubview:firstVC.view]; } - (void)dealloc { [firstVC release]; [secondVC release]; [super dealloc]; } @end </code></pre> <p>In the <code>valueChanged</code> method you replace the current view and animate the transition.</p> <p>Note that the views <code>firstVC.view</code> and <code>secondVC.view</code> are created on first access of the view-property of each VC.</p>
 

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