简体   繁体   English

我们可以为一个View Controller使用两个不同的Xib吗?

[英]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.

相关问题 具有两个不同的XIB的View Controller..Tricky - View Controller With two different XIB's..Tricky 我们可以将两个独立的xib用于iPhone和iPad的一个视图控制器吗 - Can we use Two separate xib's for iPhone & iPad for one viewcontroller 如何在一个视图控制器中将xib加载到两个容器视图中 - How to load xib into two Container Views within one view controller 如何使用具有XIB设计的View Controller中的Segues? - How to use segues from view controller that has a XIB for it's design? 我们可以使用initWithNibName来重用具有不同视图的相同.xib文件吗? - Can we use initWithNibName to reuse same .xib file with different views? 可以在UITableViewCells中使用视图控制器的xib中定义的UITextField吗? - Can UITextFields defined in a view controller's xib be used in UITableViewCells? 您可以使用为带有故事板的xib创建的视图控制器吗? - Can you use a view controller created for a xib with storyboards? 如何将一个视图控制器与不同的Realm类一起使用 - How can I use one view controller with different Realm classes 我们能否在导航栏上显示多个视图,而导航栏将不同的控制器作为另一视图的子视图? - Can we show more than one view with navigation bar having different controller as subview to another view? 在一个控制器中显示两个视图组件,但显示两个文件(xib / storyboard) - Show two view components in one controller but from two files (xib/storyboard)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM