可能重复: How can i load the different xibs for single class depends on current device in iOS?
我开发了一个通用的app.i实现了iPhone .now的应用程序,我必须为iPad实现这个应用程序。我有完整的代码,关于数据处理是在视图控制器和视图控制器. and是用于iPhone。如何使用iPad的代码。
我为ipad.when创建了一个xib文件(ipad.when),我在iPad im中运行应用程序,获取ipad,但是数据没有显示。
如何获得viewController中的数据?
谢谢你..。
发布于 2013-01-17 10:18:31
iOS有一种为iPad和iPhone加载不同NIB的简单方法。
如果您将NIB文件命名为:ViewController~ipad.xib或ViewController~iphone.xib,iOS将加载相应的文件。
我只将~ipad视图添加到我的通用项目中,这个没有任何设备说明符的NIB将被加载到所有其他设备上。
现在只需加载UIViewController,如下所示:
[[UIViewController alloc] alloc] initWithNibName:@"ViewController" bundle:nil];这也适用于图像:
back.png //Normal images
back@2x.png // Retina images
back~ipad.png // iPad normal image
back@2x~ipad.png // Retina iPad images发布于 2013-01-17 10:13:10
在app委托中添加此方法
+(NSString *)getNibName:(NSString *)strNibName
{
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
return strNibName;
else
NSLog(@"%@",[NSString stringWithFormat:@"%@_iphone",strNibName]);
return [NSString stringWithFormat:@"%@_iphone",strNibName];
}当你需要的时候打电话给这个
ViewController *obj=[[ViewController alloc] initWithNibName:[AppDelegate getNibName:@"ViewController"] bundle:nil];
[self.navigationController pushViewController:obj animated:YES];发布于 2013-01-17 10:11:15
首先您必须检查的是iPad xib中的文件所有者,xib应该与iPhone xib的控制器相同。然后,按照您在iPhone xib组件中创建的所有连接,这样就可以工作了。
https://stackoverflow.com/questions/14376485
复制相似问题