2

Using Xcode 6 beta 6 developing an iOS application that is universal application. I am facing an issue with connecting IBOutlets and using universal storyboards. If i am using "w any h any" configuration then i am not able to design two different interfaces for iPhone and iPad. if i design using different configurations i.e "w compact h regular" for iPhone and "w regular h regular" for iPad then i am able to design two different interfaces but not able to connect Same IBoutlet to both of them. If i connect it to iPhone configuration i.e "w compact h regular" first it runs smooth but as soon as i connect it to iPad configuration i.e "w regular h regular" then the connection with iPhone get disconnected automatically. Pls help me out i am not able to get a solution i have searched a lot on google but couldn't find anything as not many resources are available on this.

EDIT If i connect IBOutlets to the view in "w any h any" configuration and then switch to iPhone configuration and add constraints there storyboard displays some errors like conflicting constraints. Pls see the image

error when added constraints in

This is for iPhone configuration after connecting the outlets in "w any h any" and adding constraints in iPhone configuration

4

2 回答 2

0

我不确定这是否是不好的做法,但是当我使我的应用程序通用时,我复制了我的 viewController 并将它们与适当的故事板链接起来。我有一个名为的故事板iPadStoryboard.storyboard,它与iPadViewController.swift. 另一个故事板被命名iPhoneStoryboard.storyboard,它与iPhoneViewController.swift. 希望这可以帮助!如果效率低,请见谅!

于 2014-11-06T22:57:49.770 回答
0

这个问题已经有一年了,但以防万一还有人还在为此苦苦挣扎,这里是解决方案。

如果您计划在多个布局中连接相同的 IBOutlet,则需要将其布置在 Any - Any 布局中,然后首先将其连接到代码中的 IBOutlet。还要避免编译器警告为其设置一些约束,即使您永远不会使用该特定布局。

例如,假设您的通用应用程序设置为仅在 iPhone 或 iPad 上纵向运行,并且假设要添加一个 textField 和一个按钮。首先选择 Any-Any 并将 textField 放置在屏幕的死点并为此设置一个约束,然后将按钮放在它的正下方并将其约束在那里,然后将它们中的每一个连接到您的代码。

接下来为纵向 iPhone 切换到 Compact-Regular,然后将 textField 向下拖动到屏幕的左下部分并放置一个约束以将其保留在那里,并将按钮放在它旁边并对其进行约束。您不需要将这些重新连接到代码。自从您在 Any-Any 布局上执行此操作后,它们保持连接。现在切换到Regular-Regular 布局并重复刚才所做的相同操作,但这次将按钮和textField 放在屏幕的右上角并将它们约束在那里。

而已。它们仍然连接到代码,但约束将根据设备正确应用。如果您在纵向 iPhone 上运行该应用程序,按钮和 textField 将显示在屏幕的左下方,在 iPad 上它们将显示在右上角。如果您将 iPhone 切换到横向,它们将被限制在中心,因为这是您将它们放在 Any-Any 布局上的位置。所有这些都连接到您在 Any-Any 布局上将它们连接到的同一个 IBOutlet。

但是请注意,如果您对 Any-Any 布局进行更改,它将影响其他布局。所以首先布局 Any-Any 并确保它是正确的,然后切换到其他的并根据需要进行更改。

希望这可以帮助!

于 2015-08-16T04:46:04.840 回答