开发者

How do you switch to a split view. If you don't start with one

开发者 https://www.devze.com 2023-01-04 10:21 出处:网络
I\'m looking to find out how to switch to a UISplitView from another view. The user will c开发者_C百科lick on a button and the Split View should open. I\'m having no luck at all.

I'm looking to find out how to switch to a UISplitView from another view. The user will c开发者_C百科lick on a button and the Split View should open. I'm having no luck at all.

I start with a normal view and when the user clicks on the button i try to switch to the split view by removing the current view and initing the split view controller. I would just use a nib to load it but split views don't have nib files.

Is there anyone that can get me the simplest way to do this.


You have to create the UISplitViewController programatically. You have to give it an array of two UIViewController objects (these can be from nib files). Then when you want to load the split view you send the message [window addSubView:splitViewController.view]


i have practically done something like this.

i declared a SplitViewController in viewDidLoad at one of my viewcontroller (FrameViewController)

Then i added the splitViewController that i have just declared into AppDelegate's window variable. (i have tried declaring another UIWindow variable and add SplitViewController's view to it, it will throw wait_fences: failed to receive reply: 10004003 when u change orientation)

then, set your viewController's view to hidden so that the SplitViewController will be displayed correctly.. Voila~

- (void)viewDidLoad {
[super viewDidLoad];

appDelegate = (iPadProject2AppDelegate *)[[UIApplication sharedApplication] delegate];

ContentViewController* secondVC = [[ContentViewController alloc]
                                     initWithNibName:@"ContentView" bundle:nil];

MenuViewController* firstVC = [[MenuViewController alloc] 
                               initWithNibName:@"MenuView" 
                               bundle:nil 
                               withContentViewController:secondVC];

UISplitViewController* splitVC = [[UISplitViewController alloc] init];
splitVC.viewControllers = [NSArray arrayWithObjects:firstVC, secondVC, nil];

[appDelegate.window addSubview:splitVC.view];

[self.view setHidden:YES];}


BTW, you should add these code into Yit Ming's code:

[[self view] removeFromSuperview];

Or the Split View will not work while you change the orientation.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号