[英]Can we use Two different Xib's for one View Controller?
I have two different xib's. 我有两个不同的xib。 Let say we have created one xib for iPhone & another for iPad.
假设我们为iPhone创建了一个xib,为iPad创建了另一个xib。 I wanted to know how can we pass iPad xib's outlet referencing properties to the viewcontroller properties, already been set by the iPhone Xib.
我想知道如何将iPad xib的插座引用属性传递给已经由iPhone Xib设置的viewcontroller属性。
I know one way of implementation is by using Size class. 我知道一种实现方法是使用Size类。 But i want to know how can we implement from the above approach.
但我想知道如何从上述方法实施。
Set two Xib and set name like that 设置两个Xib并设置这样的名称
1.ViewController_ipad.XIB for ipad 1.ViewController_ipad.XIB for ipad
2.ViewController.XIB for iphone 2.ViewController.XIB for iphone
When you run your Project in iPhone while open iphone xib. 在打开iphone xib的同时在iPhone中运行Project。 When you run your Project in iPad while open ipad xib.
在打开ipad xib的同时在iPad中运行Project。
and set logic like that 并设置这样的逻辑
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) { ViewController *tempView = [[ViewController alloc] initWithNibName:@"ViewController_ipad" bundle:nil]; [self.navigationController pushViewController:tempView animated:YES]; } else { ViewController *tempView = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; [self.navigationController pushViewController:tempView animated:YES]; }
Yes we can use two different xib's for same viewController. 是的,我们可以为同一个viewController使用两个不同的xib。 Following is one example where we want different xib for iPhone and iPad.
以下是我们希望iPhone和iPad使用不同xib的一个示例。
NSString* nibName = @"ProgressViewController";
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
nibName = @"ProgressViewController_iPad";
ProgressViewController * view = [[ProgressViewController alloc] initWithNibName:nibName bundle:nil];
[self.navigationController pushViewController:view animated:YES]; // Optional if you have used navigation controller at root
Yes. 是。 You can use two xibs in single view controller.
您可以在单视图控制器中使用两个xib。 Using this you can switch to other nib.
使用此功能,您可以切换到其他笔尖。 (Xib) NSString* nib = @"ViewController";
(Xib)NSString * nib = @“ViewController”;
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
nib = @"ViewController_iPad";
ViewController * view = [[ViewController alloc] initWithNibName:nib bundle:nil];
[self.navigationController pushViewController:view animated:YES];
You can bind same functions with other nib objects but you have to bind every object with different names 您可以将其他nib对象绑定到相同的函数,但必须使用不同的名称绑定每个对象
Like :- your label in ViewController apple So you can put label name in ViewController_iPad apple_iPad.
喜欢: - 您在ViewController中的标签apple所以您可以将标签名称放在ViewController_iPad apple_iPad中。
It means you can use same function in both nibs but you have to use diff object bindings for both. 这意味着您可以在两个笔尖中使用相同的功能,但必须对两者使用diff对象绑定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.