One UIViewcontroller, how to switch between multiple xibs?

I have a subclass UIViewController:

 @interface KBViewController : UIViewController

with multiple xibs, for example, one is this Qwertyand the other is Dvoraklayout:

 KBViewControllerQuerty~iphone.xib
 KBViewControllerDvorak~iphone.xib

Therefore, when the user presses the button, Qwertyswitches to Dvorak. As you can see, the code logic is identical for both keyboard layouts. I need to reboot to viewothers xib.

We hope that all buttons in Dvorak xibwill be associated with the answer IBOutletin KBViewController.

What is the correct way to switch between two xibs?

+5
source share
2 answers

Nibs File Owner. IBOutlet IBAction File Owner. , Nibs, Nib File Owner .

, File Owner KBViewController *.xib KBViewController KBViewController -, KBViewController *.xib, initWithNibNamed ( )

KBViewController, KBViewController Nib. KBViewController.m loadView UIView -[NSBundle loadNibNamed] ( self.view ).

UIView *someView = [[[NSBundle mainBundle] loadNibNamed:@"SomeNibFile"
                                                  owner:self
                                                options:nil] objectAtIndex:0];
self.view = someView;

owner:self . File Owner @ "SomeNibFile".

:

id superview = self.view.superview;
[self.view removeFromSuperview];
UIView *someView = [[[NSBundle mainBundle] loadNibNamed:@"SomeNibFile"
                                                  owner:self
                                                options:nil] objectAtIndex:0];
self.view = someView;
[superview addSubview:self.view];

: -

+6

nib view , , .

    UIView *someView = [[[NSBundle mainBundle] loadNibNamed:@"SomeNibFile"
                                                      owner:self
                                                    options:nil] objectAtIndex:0];

objectAtIndex:0 , nib UIView

self.view = someView;

, , .

0

All Articles