简体   繁体   中英

MGSplitViewController change detail view controller

Using MGSplitViewController, how do I change the detail view controller? There's a property declared:

@property (nonatomic, retain) IBOutlet UIViewController *detailViewController; // convenience.

doing splitVC.detailViewController = myVC; has not effect. Instead I have to do splitVC.viewControllers = @[masterVC, myVC]; . It works, but is this the right way?

Thanks!

You are doing it right. From UISplitViewController Reference:

The split view controller has no significant interface of its own . Its job is to manage the presentation of its two child view controllers and transitions between different orientations.

also:

You must assign two view controllers to a split view controller. Usually you configure these view controllers in a storyboard; if you create a split view controller programmatically, you assign them using the viewControllers property .

When using MGSplitViewController , a way to set the detailViewController without resetting everything (which seems very inefficient) is to set the detailViewController and then call layoutSubviews

splitViewController.detailViewController = myVC;
[splitViewController layoutSubviews];

This avoids the wasteful overhead of removing the master viewcontroller's view and then resetting it.

Hope this helps!

No it isn't the right way,instead allocate your master and detail viewcontroller in navigationcontroller like UINavigationController *nav1 = [UINavigationController alloc]initwithrootviewcontroller:masterviewcontroller]; likewise nav2 for detail.Then write

splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:nav1,nav2, nil];
splitViewController.delegate = detailViewController;

Thats it. Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM