iOs特定于设备的资源不起作用 - ~iPad加载默认XIB - 通用应用程序

时间:2023-01-23 13:03:08

I'm making a universal app based on the Utility App template. I've selected a universal app and the MainView.xib and MainView~iPad.xib work properly on both device types.

我正在基于Utility App模板制作通用应用程序。我选择了一个通用应用程序,MainView.xib和MainView~iPad.xib在两种设备类型上都能正常工作。

On the iPad2, when I switch to the FlipsideView, it loads FlipsideView.xib even though there is a perfectly good FlipsideView~iPad.xib file in the project. The default xib is normal (iPhone) sized and displaying in the lower left hand corner of the iPad.

在iPad2上,当我切换到FlipsideView时,它会加载FlipsideView.xib,即使项目中有一个非常好的FlipsideView~iPad.xib文件。默认的xib是正常的(iPhone)大小并显示在iPad的左下角。

I did have to create the FlipsideView~iPad xib manually. I believe I have the xib properly wired in IB as it shows identical to the FlipsideView.xib connections.

我必须手动创建FlipsideView~iPad xib。我相信我已经在IB中正确连接了xib,因为它显示与FlipsideView.xib连接相同。

Over the last couple weeks, I've read quite a few posts with similar problems and this Stack Overflow thread answers most clearly and contains links to Apple documentation. So I know it works for others and is documented.

在过去的几周里,我已经阅读了很多类似问题的帖子,这个Stack Overflow线程回答得最清楚,并包含Apple文档的链接。所以我知道它适用于其他人并且有记录。

The code for this section is identical to the showInfo() method in the stock Utility App template.

此部分的代码与库存Utility App模板中的showInfo()方法相同。

(Yes I realize I can manually load the ~iPad version checking UI_USER_INTERFACE_IDIOM(). I'm trying to figure out what I'm doing wrong in getting the ~iPad modifier to work.)

(是的,我意识到我可以手动加载~iPad版本检查UI_USER_INTERFACE_IDIOM()。我正在试图弄清楚我在做什么错误让~iPad修饰符起作用。)

Any ideas what I'm missing?

我缺少什么想法?

Thanks a ton for your help!

非常感谢您的帮助!

2 个解决方案

#1


27  

in the end i found the solution. it is really very very simple. The xib must be named ~ipad instead of ~iPad, and ~iphone instead of ~iPhone. The bad thing is the if you name them ~iPad, everything works in the simulator but it does not work on the real device.

最后我找到了解决方案。这真的很简单。 xib必须命名为~ipad而不是~iPad,而@ iphone而不是~iPhone。不好的是,如果你给它们命名~iPad,一切都在模拟器中工作,但它不适用于真实设备。

#2


0  

It can be done automatically based on the name, no worries. The only problem is you'll need to switch your naming convention. MainView.xib will be your iPad xib and MainView~iphone.xib will be your iPhone xib. Then it should work perfectly for you and you don't have to do anything but alloc/init.

它可以根据名称自动完成,无后顾之忧。唯一的问题是你需要切换你的命名约定。 MainView.xib将是你的iPad xib和MainView~iphone.xib将是你的iPhone xib。然后它应该适合你,除了alloc / init之外你不需要做任何事情。

You can check out my other answer on this topic here: iOS: Using device modifiers for loading xib files?

你可以在这里看看我对这个主题的另一个答案:iOS:使用设备修改器加载xib文件?

#1


27  

in the end i found the solution. it is really very very simple. The xib must be named ~ipad instead of ~iPad, and ~iphone instead of ~iPhone. The bad thing is the if you name them ~iPad, everything works in the simulator but it does not work on the real device.

最后我找到了解决方案。这真的很简单。 xib必须命名为~ipad而不是~iPad,而@ iphone而不是~iPhone。不好的是,如果你给它们命名~iPad,一切都在模拟器中工作,但它不适用于真实设备。

#2


0  

It can be done automatically based on the name, no worries. The only problem is you'll need to switch your naming convention. MainView.xib will be your iPad xib and MainView~iphone.xib will be your iPhone xib. Then it should work perfectly for you and you don't have to do anything but alloc/init.

它可以根据名称自动完成,无后顾之忧。唯一的问题是你需要切换你的命名约定。 MainView.xib将是你的iPad xib和MainView~iphone.xib将是你的iPhone xib。然后它应该适合你,除了alloc / init之外你不需要做任何事情。

You can check out my other answer on this topic here: iOS: Using device modifiers for loading xib files?

你可以在这里看看我对这个主题的另一个答案:iOS:使用设备修改器加载xib文件?