gpt4 book ai didi

iphone - 将多个 XIB 文件添加到任何文件

转载 作者:行者123 更新时间:2023-11-28 22:27:14 25 4
gpt4 key购买 nike

我想添加一个 XIB 文件 ..我有一个 UIViewcontroller 子类文件 ..现在有了一个 ipad XIB 我想要一个带有 iphone 的 XIB 文件 ..

New File> User Interface >View ,我添加了新的 XIB ...现在我该如何配置我现有的 .h .m 。我无法连接 File Owner 导出属性并通过使用代码如果我运行这个 XIB 文件,给我一个粗鲁的错误提示

* 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-[UIViewController _loadViewFromNibNamed:bundle:] 加载了“AViewController_iphone” Nib ,但未设置 View socket 。”

我需要在 XIB 中进行哪些更改才能与我的 .h .m 一起使用

最佳答案

enter image description here

打开 xib 然后点击 FIle OWner ..然后打开 Identity Inspector 然后在 Custom Class 部分,输入你想要链接的类名,之后,你会看到你所有的连接在文件所有者中。

然后转到 .m 文件用这个替换以前的方法 ...

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
//MainMenu_iPad is xib for iPad and MainMenu is for iPhone
NSString *nib = (isiPad) ? @"MainMenu_iPad" : @"MainMenu";
self = [super initWithNibName:nib bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

在.h文件中

#define isiPad      ([[UIDevice  currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPad)

关于iphone - 将多个 XIB 文件添加到任何文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18569858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com