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 "w compact h regular"

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

Rohit
  • 1,189
  • 12
  • 23
  • Can you add the object to Any-Any, wire up the outlet, and then switch to Compact-Regular and Regular-Regular to handle the layout constraints? – vacawama Aug 21 '14 at 11:20
  • Yes i can add that but after that constraint management is not so easy. storyboards start giving error like conflicting constraints. – Rohit Aug 21 '14 at 11:55
  • Doing anything to iPhone constraints affect iPad too. – Rohit Aug 21 '14 at 11:58
  • @vacawama i have added the image in edit pls see it and help me. – Rohit Aug 21 '14 at 12:08
  • I'm just learning the new IF myself. Start by clicking on the Stop Sign icon and seeing what options it gives you. I have been able to layout button locations differently for iPad and iPhone. I've been using Compact-Any for iPhone and Regular-Any for iPad. – vacawama Aug 21 '14 at 14:06
  • @vacawama Clicking on that opens a window and deleting once constraints out of two causes the width of button to increase and that affects iPad too. – Rohit Aug 22 '14 at 04:21

2 Answers2

0

I'm not sure if this is bad practice, but when I made my app universal, I duplicated my viewControllers and linked them with the appropriate storyboards. I had one storyboard named iPadStoryboard.storyboard which was linked with iPadViewController.swift. The other storyboard was named iPhoneStoryboard.storyboard which was linked with iPhoneViewController.swift. Hope this helps! Sorry if it is inefficient!

Logan
  • 828
  • 7
  • 10
0

This question is a year old, but just in case there are folks still struggling with this, here is the solution.

If you are planning on hooking up the same IBOutlet in multiple layouts it is required that you lay it out in the Any - Any layout and connect it to the IBOutlet in your code from there first. Also to avoid compiler warnings setup some constraints for it, even if you will never use that particular layout.

For example lets say your universal app is setup to only run in portrait on either iPhone or iPad, and lets say want to add a textField and a button. First select Any-Any and place the textField dead center of the screen and set a constraint for that, then put the button right below it and constrain it there as well, and then connect each of them to your code.

Next switch to Compact-Regular for portrait iPhones, and drag the textField down to the lower left part of the screen and put a constraint to keep it there, and place the button right next to it and constrain it as well. You DO NOT need to reconnect these to the code. They remain connected since you did that on the Any-Any Layout. Now switch to the Regular-Regular layout and repeat the same thing you just did, but this time put the button and textField in the upper right hand side of the screen and constrain them there.

That's it. They are still connected to the code, but the constraints will apply correctly based on the device. If you run the app on a portrait iPhone the button and textField will be displayed on the lower left of the screen, on an iPad they will display on the upper right. If you switch your iPhone to landscape they will be constrained to the center since that is where you put them on the Any-Any layout. All of these are connected to the same IBOutlet that you connected them to on the Any-Any layout.

Be forewarned however, that if you make changes on the Any-Any layout it will affect the others. So layout Any-Any first and make absolutely sure it is correct, then switch to the other ones and make changes as necessary.

Hope this helps!

Scooter
  • 4,068
  • 4
  • 32
  • 47