Converting Storyboard from iPhone to iPad - ios

I have an iPhone application which has a storyboard. Now I want to provide an iPad application too. So I asked me whether there is a function which helps me convert my iPhone storyboard to an iPad storyboard.
To be specific:
Is there a similar function or is there only the manual way ?

I found out a kind of solution:
Duplicate your iPhone-Storyboard and rename it MainStoryboard_iPad.storyboard
Close Xcode and then open this file any text editor.
Search for targetRuntime="iOS.CocoaTouch"and change it to targetRuntime="iOS.CocoaTouch.iPad"
Change the code in the MainStoryboard_iPad.storyboard from:
<simulatedScreenMetrics key="destination" type="retina4"/> to
<simulatedScreenMetrics key="destination"/>
Now save everything and reopen Xcode. The iPad-Storyboard has the same contents as the iPhone-file but everyting could be disarranged.
This saved me hours - hopefully this will help you

If you had created a universal project, by default empty iPad storyboard would have been created, you just have to select iPhone storyboard select all (Command+A), copy (Command+C) and paste it on iPad storyboard. Make sure to move the entry point from the empty storyboard to newly copied storyboard before compiling.

That didn't quite work for me. I did something a little bit different.
Create a new story board file for the iPad version
Open both the new file and the file i want to copy in textwrangler (text editor)
Copied the xml text from old file to the new file between these xml tags
First Tag <scenes> <!--Contents View Controller-->
Paste Here
End Tags </class> </classes>
That worked for me. I got a new layoutout with all my outlets connected, which alone saved me a few hours.

From reading many threads on stackoverflow i discovered the solution is-
1.Duplicate your iPhone-Storyboard and rename it MainStoryboard_iPad.storyboard
2.right click on the storyboard -> “open as” -> “Source Code”.
3.Search for targetRuntime="iOS.CocoaTouch"and change it to targetRuntime="iOS.CocoaTouch.iPad"
5.Search for <simulatedScreenMetrics key="destination" type="retina4"/> and change it to to <simulatedScreenMetrics key="destination"/>
4.Now save everything and right click on MainStoryboard_iPad.storyboard “open as” ->"IOS StoryBoard"
5. you may also have to change your constraints.
Thats all you have done.

1. Create New Storyboard file with MainStoryboard_iPad.storyboard
2. Copy All the views from MainStoryboard and paste to MainStoryboard_iPad.storyboard

1 - Create your "MainStoryboard_iPad.storyboard";
2 - Right-click on you "MainStoryboard_iPhone.storyboard" and "Open as -> Source Code". Copy everything;
3- Right-click on you "MainStoryboard_iPad.storyboard" and "Open as -> Source Code". Paste everything. Now Search and change:
targetRuntime="iOS.CocoaTouch" to targetRuntime="iOS.CocoaTouch.iPad"
type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" to type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.iPad.XIB"
4 - Save. Now reopen but using the interface builder. You will only have to re-arrange.
This method can be used for .xib files too

This is going the other way, but I was able to do a select all & copy in my iPad storyboard (~35 scenes) and paste it into my iPhone storyboard. The scene sizes were automatically adjusted. I only saw two problems, I had to replace UISplitViewController (since it's only iPad), and the default background became transparent instead of gray (still working on fixing that properly, without manually setting the background for everything).
EDIT: It seems the default background for UITableView in the Attributes inspector is rather strange. I had to manually set the background to "Group Table View Background Color" for grouped table views, and "White Color" for non-grouped table views. It then was displayed as "Default" (I assume since it then matched a hardcoded value). -- Actually, even easier, changing from "Grouped" to "Static" and back seems to reset the default color.

Here's something that saved me hours and might help those of you with Python skills.
I've been building an app for the last two months, focused on just iPad iterating the UX with the team.
Today focused on building out iPhone version, followed the steps above (thanks!) but I didn't want to then have to resize all the ui elements from iPad dimensions in the visual storyboard editor.
So I wrote this little python jig script to scan through the storyboard file for x, y, width, height and scale everything down by by ratio 320./768. Allowed me then to just focus on fine adjustments.
Copy your iPad storyboard into a new file. (e.g. iPhoneStoryboard.storyboard)
Run the script below with the copied storyboard filename as the first parameter.
Will generate output file with suffix _adjusted.storyboard (e.g. iPhoneStoryboard.storyboard_adjusted.storyboard)
Hope it helps...
import re
import sys
import math
afile = sys.argv[1]
scale = 320./768.
number_pattern = '[-0-9]+(.[0-9]+)?'
#width_pattern = 'width="[-0-9]+( ?px)?"'
width_pattern = 'width="[-0-9]+(.[0-9]+)?( ?px)?"'
height_pattern = 'height="[-0-9]+(.[0-9]+)?( ?px)?"'
x_pattern = 'x="[-0-9]+(.[0-9]+)?( ?px)?"'
y_pattern = 'y="[-0-9]+(.[0-9]+)?( ?px)?"'
def replacescaledvalue(scale,pattern,sometext,replacefmt) :
ip = re.search(pattern, sometext, re.IGNORECASE)
if(ip) :
np = re.search(number_pattern,ip.group(0))
if(np) :
val = float(np.group(0))
val = int(math.floor(val*scale))
sval = replacefmt+str(val)+'"'#+'px"'
newtext = re.sub(pattern,sval,sometext)
return newtext
else :
return sometext
fin = open(afile)
fout = open(afile+"_adjusted.storyboard", "wt")
for line in fin:
newline = line
newline = replacescaledvalue(scale,width_pattern,newline,'width="')
newline = replacescaledvalue(scale,height_pattern,newline, 'height="')
newline = replacescaledvalue(scale,x_pattern,newline, 'x="')
newline = replacescaledvalue(scale,y_pattern,newline, 'y="')
# print newline
fout.write( newline )
fin.close()
fout.close()

For Xcode10
Just duplicate Main.storyboard
Then re-name files to Main_iPad.storyboard and Main_iPone.storyboard
Set appropriate names in .plist
4.Just select the proper .storyboard to configure

Go to your Target Summary and change devices to universal,
then go down and set the ipad version to any storyboard you like including a copied and renamed one if you like.

Just as a quick gotcha note to those who may have had my issue with this:
My issue:
The storyboard content copied over nicely to a new board file I added. However, it would not put changes over to my provisioned iPad. Noticing that I had to switch over the designated storyboard for the build target (see image) let the changes show.
I'd post an image if I had the points, but the setting is located in:
Project navigator on the left side source menu, root target of project (center pane) general tab, (second subhead) deployment info, with the iPad button tab selected.
From there, choose your storyboard under "main interface."
Thanks for the post, I hope this mention helps a snag somewhere.

Just for fun, on XCode 5.1 and iOS 7.1 I also needed to change the values of "toolVersion" and "systemVersion" to this:
toolsVersion="5023" systemVersion="13A603"
Without this, the new storyboard file wouldn't compile

Using the XCode6 Size Classes you no longer need to convert the storyboard to iPad.
The same Storyboard can be used for both the iPhone and the iPad, saving you from keeping two files up to date.
The resulting storyboard is compatible with iOS7+.
Read more about this here:
https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/AboutAdaptiveSizeDesign.html#//apple_ref/doc/uid/TP40014436-CH6-SW1
Use size classes to enable a storyboard or xib file to work with all available screen sizes. This enables the user interface of your app to work on any iOS device.

This functionality is now built-in. For example, if one changes the project settings in Deployment Info -> Devices from iPhone to Universal, the following dialog will show up:

There is a really simple solution for Xcode versions that support size classes (Tested in Xcode 7 which is the current version at the time of writing). Check the "use size classes" checkbox on a storyboard file (File Inspector), confirm that dialog that appears. Then uncheck that same checkbox - Xcode will ask you if you want to use this storyboard with an iPhone or iPad, and convert the screens in it appropriately. No need to directly edit the storyboard file. For both iPad and iPhone, just copy the same storyboard and configure one for iPad and one for iPhone using the described method.
And Before someone suggest to use size classes - while great, they are less convenient for heavily customized UI, such as games etc

I followed this thread when I was hit with the same issue yesterday. The steps I followed
For Xcode 5.1, I had to do some cleanup of iPhone storyboard like missing reuseIdentifiers of Table cells, provide story board id for every controller, remove unused scenes.
Copy MainStoryboard_iPhone.storyboard to MainStoryboard_iPad.storyboard.
Using vi editor - changed targetRuntime="iOS.CocoaTouch" to targetRuntime="iOS.CocoaTouch.iPad"
Change the code in the MainStoryboard_iPad.storyboard from: <simulatedScreenMetrics key="destination" type="retina4"/> to <simulatedScreenMetrics key="destination"/>
Open the project in Xcode.
Changed the Deployment devices to Universal - Chose the option of NOT copying the iPhone Storyboard.
Xcode will default the Deployment Target to 7.1, took care of the deprecated functions.
To fix the misplaced view error in iPad Storyboard - Changed the Frame Layout for Controllers giving errors.
That was it.. Thanks all for your help..

The easiest and most reliable way to do this is to copy paste from your iPad storyboard.
Create a new storyboard and name it something like MainStoryboard_ipad.
Make your app a Universal app by setting the Devices property to Universal on the Summary page of the Target properties for your project.
Open your iPhone storyboard and select all and copy
Open your iPad storyboard and paste.
You'll have to go about resizing, but it can be faster than recreating the whole storyboard.

A Different Approach
Add an empty-View-Controller with Navigation-Controller in the iPad-Storyboard
Change the Class to the Class of your first ViewController used for iPhone, "fooViewController"
Add the Storyboard-Identifier in the iPhone-Storyboard "fooViewController_storyboard_identifier" for the first ViewController
Go to "fooViewController.m"
Add bool Variable bool nibWasLoadForIpad=false
Go to viewDidLoad-Method
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && !nibWasLoadForIpad)
{
nibWasLoadForIpad=true;
UIStoryboard* Storyboard_iphone=[UIStoryboard storyboardWithName:#"Main_iPhone" bundle: nil];
fooViewController *controller = [Storyboard_iphone instantiateViewControllerWithIdentifier:#"fooViewController_storyboard_identifier"];
[self.navigationController pushViewController:controller animated:YES];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
}
(ps. Know problem is that the view-backgrounds will be set to white)

You should create a bug report with Apple. You can say it's a duplicate of mine (10167030) which has been open since September 2011. The frustrating thing from my point of view is that the feature existed in Xcode 3...

Thanks for the answers everybody.
I followed the above steps but when I ran the app under the simulator or my iPad it kept on just using the iPhone storyboard.
For some reason, when I changed the target device to be Universal instead of iPhone, Xcode (v5.0) didn't update the app-Info.plist file to include the iPad storyboard, so I had to manually add the following entry (using the plist editor in Xcode):
Main storyboard file base name (iPad) ==> MainStoryboard_iPad

I just change (additionally to the answer from #tharkay):
<device id="ipad9_7" orientation="landscape">
and works great !
I use this in XCode 8.3.3

Related

Converting iOS Storyboard to tvOS [duplicate]

I have an iPhone application which has a storyboard. Now I want to provide an iPad application too. So I asked me whether there is a function which helps me convert my iPhone storyboard to an iPad storyboard.
To be specific:
Is there a similar function or is there only the manual way ?
I found out a kind of solution:
Duplicate your iPhone-Storyboard and rename it MainStoryboard_iPad.storyboard
Close Xcode and then open this file any text editor.
Search for targetRuntime="iOS.CocoaTouch"and change it to targetRuntime="iOS.CocoaTouch.iPad"
Change the code in the MainStoryboard_iPad.storyboard from:
<simulatedScreenMetrics key="destination" type="retina4"/> to
<simulatedScreenMetrics key="destination"/>
Now save everything and reopen Xcode. The iPad-Storyboard has the same contents as the iPhone-file but everyting could be disarranged.
This saved me hours - hopefully this will help you
If you had created a universal project, by default empty iPad storyboard would have been created, you just have to select iPhone storyboard select all (Command+A), copy (Command+C) and paste it on iPad storyboard. Make sure to move the entry point from the empty storyboard to newly copied storyboard before compiling.
That didn't quite work for me. I did something a little bit different.
Create a new story board file for the iPad version
Open both the new file and the file i want to copy in textwrangler (text editor)
Copied the xml text from old file to the new file between these xml tags
First Tag <scenes> <!--Contents View Controller-->
Paste Here
End Tags </class> </classes>
That worked for me. I got a new layoutout with all my outlets connected, which alone saved me a few hours.
From reading many threads on stackoverflow i discovered the solution is-
1.Duplicate your iPhone-Storyboard and rename it MainStoryboard_iPad.storyboard
2.right click on the storyboard -> “open as” -> “Source Code”.
3.Search for targetRuntime="iOS.CocoaTouch"and change it to targetRuntime="iOS.CocoaTouch.iPad"
5.Search for <simulatedScreenMetrics key="destination" type="retina4"/> and change it to to <simulatedScreenMetrics key="destination"/>
4.Now save everything and right click on MainStoryboard_iPad.storyboard “open as” ->"IOS StoryBoard"
5. you may also have to change your constraints.
Thats all you have done.
1. Create New Storyboard file with MainStoryboard_iPad.storyboard
2. Copy All the views from MainStoryboard and paste to MainStoryboard_iPad.storyboard
1 - Create your "MainStoryboard_iPad.storyboard";
2 - Right-click on you "MainStoryboard_iPhone.storyboard" and "Open as -> Source Code". Copy everything;
3- Right-click on you "MainStoryboard_iPad.storyboard" and "Open as -> Source Code". Paste everything. Now Search and change:
targetRuntime="iOS.CocoaTouch" to targetRuntime="iOS.CocoaTouch.iPad"
type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" to type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.iPad.XIB"
4 - Save. Now reopen but using the interface builder. You will only have to re-arrange.
This method can be used for .xib files too
This is going the other way, but I was able to do a select all & copy in my iPad storyboard (~35 scenes) and paste it into my iPhone storyboard. The scene sizes were automatically adjusted. I only saw two problems, I had to replace UISplitViewController (since it's only iPad), and the default background became transparent instead of gray (still working on fixing that properly, without manually setting the background for everything).
EDIT: It seems the default background for UITableView in the Attributes inspector is rather strange. I had to manually set the background to "Group Table View Background Color" for grouped table views, and "White Color" for non-grouped table views. It then was displayed as "Default" (I assume since it then matched a hardcoded value). -- Actually, even easier, changing from "Grouped" to "Static" and back seems to reset the default color.
Here's something that saved me hours and might help those of you with Python skills.
I've been building an app for the last two months, focused on just iPad iterating the UX with the team.
Today focused on building out iPhone version, followed the steps above (thanks!) but I didn't want to then have to resize all the ui elements from iPad dimensions in the visual storyboard editor.
So I wrote this little python jig script to scan through the storyboard file for x, y, width, height and scale everything down by by ratio 320./768. Allowed me then to just focus on fine adjustments.
Copy your iPad storyboard into a new file. (e.g. iPhoneStoryboard.storyboard)
Run the script below with the copied storyboard filename as the first parameter.
Will generate output file with suffix _adjusted.storyboard (e.g. iPhoneStoryboard.storyboard_adjusted.storyboard)
Hope it helps...
import re
import sys
import math
afile = sys.argv[1]
scale = 320./768.
number_pattern = '[-0-9]+(.[0-9]+)?'
#width_pattern = 'width="[-0-9]+( ?px)?"'
width_pattern = 'width="[-0-9]+(.[0-9]+)?( ?px)?"'
height_pattern = 'height="[-0-9]+(.[0-9]+)?( ?px)?"'
x_pattern = 'x="[-0-9]+(.[0-9]+)?( ?px)?"'
y_pattern = 'y="[-0-9]+(.[0-9]+)?( ?px)?"'
def replacescaledvalue(scale,pattern,sometext,replacefmt) :
ip = re.search(pattern, sometext, re.IGNORECASE)
if(ip) :
np = re.search(number_pattern,ip.group(0))
if(np) :
val = float(np.group(0))
val = int(math.floor(val*scale))
sval = replacefmt+str(val)+'"'#+'px"'
newtext = re.sub(pattern,sval,sometext)
return newtext
else :
return sometext
fin = open(afile)
fout = open(afile+"_adjusted.storyboard", "wt")
for line in fin:
newline = line
newline = replacescaledvalue(scale,width_pattern,newline,'width="')
newline = replacescaledvalue(scale,height_pattern,newline, 'height="')
newline = replacescaledvalue(scale,x_pattern,newline, 'x="')
newline = replacescaledvalue(scale,y_pattern,newline, 'y="')
# print newline
fout.write( newline )
fin.close()
fout.close()
For Xcode10
Just duplicate Main.storyboard
Then re-name files to Main_iPad.storyboard and Main_iPone.storyboard
Set appropriate names in .plist
4.Just select the proper .storyboard to configure
Go to your Target Summary and change devices to universal,
then go down and set the ipad version to any storyboard you like including a copied and renamed one if you like.
Just as a quick gotcha note to those who may have had my issue with this:
My issue:
The storyboard content copied over nicely to a new board file I added. However, it would not put changes over to my provisioned iPad. Noticing that I had to switch over the designated storyboard for the build target (see image) let the changes show.
I'd post an image if I had the points, but the setting is located in:
Project navigator on the left side source menu, root target of project (center pane) general tab, (second subhead) deployment info, with the iPad button tab selected.
From there, choose your storyboard under "main interface."
Thanks for the post, I hope this mention helps a snag somewhere.
Just for fun, on XCode 5.1 and iOS 7.1 I also needed to change the values of "toolVersion" and "systemVersion" to this:
toolsVersion="5023" systemVersion="13A603"
Without this, the new storyboard file wouldn't compile
Using the XCode6 Size Classes you no longer need to convert the storyboard to iPad.
The same Storyboard can be used for both the iPhone and the iPad, saving you from keeping two files up to date.
The resulting storyboard is compatible with iOS7+.
Read more about this here:
https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/AboutAdaptiveSizeDesign.html#//apple_ref/doc/uid/TP40014436-CH6-SW1
Use size classes to enable a storyboard or xib file to work with all available screen sizes. This enables the user interface of your app to work on any iOS device.
This functionality is now built-in. For example, if one changes the project settings in Deployment Info -> Devices from iPhone to Universal, the following dialog will show up:
There is a really simple solution for Xcode versions that support size classes (Tested in Xcode 7 which is the current version at the time of writing). Check the "use size classes" checkbox on a storyboard file (File Inspector), confirm that dialog that appears. Then uncheck that same checkbox - Xcode will ask you if you want to use this storyboard with an iPhone or iPad, and convert the screens in it appropriately. No need to directly edit the storyboard file. For both iPad and iPhone, just copy the same storyboard and configure one for iPad and one for iPhone using the described method.
And Before someone suggest to use size classes - while great, they are less convenient for heavily customized UI, such as games etc
I followed this thread when I was hit with the same issue yesterday. The steps I followed
For Xcode 5.1, I had to do some cleanup of iPhone storyboard like missing reuseIdentifiers of Table cells, provide story board id for every controller, remove unused scenes.
Copy MainStoryboard_iPhone.storyboard to MainStoryboard_iPad.storyboard.
Using vi editor - changed targetRuntime="iOS.CocoaTouch" to targetRuntime="iOS.CocoaTouch.iPad"
Change the code in the MainStoryboard_iPad.storyboard from: <simulatedScreenMetrics key="destination" type="retina4"/> to <simulatedScreenMetrics key="destination"/>
Open the project in Xcode.
Changed the Deployment devices to Universal - Chose the option of NOT copying the iPhone Storyboard.
Xcode will default the Deployment Target to 7.1, took care of the deprecated functions.
To fix the misplaced view error in iPad Storyboard - Changed the Frame Layout for Controllers giving errors.
That was it.. Thanks all for your help..
The easiest and most reliable way to do this is to copy paste from your iPad storyboard.
Create a new storyboard and name it something like MainStoryboard_ipad.
Make your app a Universal app by setting the Devices property to Universal on the Summary page of the Target properties for your project.
Open your iPhone storyboard and select all and copy
Open your iPad storyboard and paste.
You'll have to go about resizing, but it can be faster than recreating the whole storyboard.
A Different Approach
Add an empty-View-Controller with Navigation-Controller in the iPad-Storyboard
Change the Class to the Class of your first ViewController used for iPhone, "fooViewController"
Add the Storyboard-Identifier in the iPhone-Storyboard "fooViewController_storyboard_identifier" for the first ViewController
Go to "fooViewController.m"
Add bool Variable bool nibWasLoadForIpad=false
Go to viewDidLoad-Method
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && !nibWasLoadForIpad)
{
nibWasLoadForIpad=true;
UIStoryboard* Storyboard_iphone=[UIStoryboard storyboardWithName:#"Main_iPhone" bundle: nil];
fooViewController *controller = [Storyboard_iphone instantiateViewControllerWithIdentifier:#"fooViewController_storyboard_identifier"];
[self.navigationController pushViewController:controller animated:YES];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
}
(ps. Know problem is that the view-backgrounds will be set to white)
You should create a bug report with Apple. You can say it's a duplicate of mine (10167030) which has been open since September 2011. The frustrating thing from my point of view is that the feature existed in Xcode 3...
Thanks for the answers everybody.
I followed the above steps but when I ran the app under the simulator or my iPad it kept on just using the iPhone storyboard.
For some reason, when I changed the target device to be Universal instead of iPhone, Xcode (v5.0) didn't update the app-Info.plist file to include the iPad storyboard, so I had to manually add the following entry (using the plist editor in Xcode):
Main storyboard file base name (iPad) ==> MainStoryboard_iPad
I just change (additionally to the answer from #tharkay):
<device id="ipad9_7" orientation="landscape">
and works great !
I use this in XCode 8.3.3

how does LaunchScreen.storyboard redirect to Main.storyboard

I'm newbie of iOS developer, and I know that is very simple question but I really can't understand reason.
when I build SingleViewApplication, Xcode auto generate LaunchScreen.storyboard and Main.storyboard,
but I can't find any code like [self.navigationController pushViewController:] which may choose that what view controller enter stack as last one of top-level view,
I only find ViewController.{h,m} as first and see no logic that change view from LaunchScreen.storyboard to Main.storyboard.
could anyone help? thanks..
Main.storyboard file and LaunchScreen is define in your project property.
you can find it by click on project in xcode and then in below target you can find this two name you can choose your own by selecting dropdown given beside label.
and other redirecting to LaunchScreen to Main.storyboard you can refer info.plist file in your project and also AppDelegate.h and AppDelegate.m
Most probably the iOS first looks for LaunchScreen.storyboard file and shows it for some time and when it is done with it, it looks for Main.storyboard.
These names are hardwired in the plist as mentioned by Tejas in his answer and you can change these.
I don't think the the LaunchScreen.storyboard is pushing the Main.storyboard. Everything is managed behind the scenes and you can't change this behavior.
What you can change is the initial View Controller in your Main.storyboard so that it is instantiated immediately after the LaunchScreen.storyboard disappears and the app is fully loaded.

iOS 8: Launch Screen StoryBoard appears black [single XIB file works fine]

So I tried creating a launch storyboard for my iOS 8 app using this tutorial
However, I only get a black screen when I launch my app. A single launch screen.xib file works perfectly, however, when I try to use a storyboard, it doesn't work.
I tried a storyboard with just a single view controller, but it still gives me a black screen, hence I believe the issue is with storyboard files in my setup. Any ideas?
[XCode version 6.4]
EDIT: So I just want to clarify that it is the launch screen that appears black. The main storyboard itself appears correctly when the app has finished loading
Read through the tutorial and tested it, and it doesn't say two things:
1: You'll need to add a UIViewController to your .storyboard file, and then select it as the Initial Controller.
2: If you wish to change more than just the launch screen, you'll have to go to the project settings and set the "Main Interface" to your corresponding .storyboard.
Once that is done, all you need to do is edit the UIButton/Label/etc connections to your ViewController classes.
EDIT:
For clarification, you can set a UIView as the initial controller by selecting it in it's respective storyboard file, then opening the Attributes Inspector. The option for 'Is Initial Controller" is towards the middle.
For people using UIImageView in the launch screen
Make sure that you are using the image name without the extension in the attributes inspector.
So for example, if your image file is named launcher.png, only use launcher as image name.
This will show the image as invalid (?) in the editor but will show correctly when run on device.
(Don't ask me why it works this way. Ask Apple.)
None of the answers have all the steps required, hence this exhaustive solution.
Storyboard
Start by creating the LaunchScreen.storyboard. Xcode > File > New > File... > Storyboard > LaunchScreen.storyboard and add it to all appropriate targets.
In this storyboard, create a single view controller of type UIViewController. Do all the magic your launch screen requires, then follow these steps:
LaunchScreen.storyboard > Show the File inspector > Use as Launch Screen
LaunchScreen.storyboard > View Controller > Show the Attributes inspector > Is Initial View Controller
Project > General > Deployment Info > Main Interface > LaunchScreen
Repeat for [iPhone] and [iPad]
Project > General > App Icons and Launch Images > Launch Screen File > LaunchScreen
If setup properly, your Info.plist should have LaunchScreen .storyboard, without the .storyboard under the UILaunchStoryboardName & UIMainStoryboardFile properties:
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>LaunchScreen</string>
Notes:
This is not incompatible with having legacy images for older devices using Launch Screen File > Assets.
Pay special attention to LaunchScreen.storyboard and Main.storyboard. One is used for launch, the other for your app entry point. They both need to have Is Initial View Controller set.
In the storyboard, which you are using for launching, please make sure that you had selected the option of Is initial view controller for the very single view controller present in it.
I Belive I may have had a similar issue that required something a littel different to the above answers.
I created a new launch screen in a .storyboard file, then after it not appearing I resulted to a new .xib file which still did not appear when the app was launched.
I figured out that some of the images I had on my launch screen had an Outlet Collection to an old .swift file. After removing this from the LaunchScree.xib's the launch screen worked fine.
Notice the litte warning sign in the outlet reference ->
Make sure that you set your entry point and in your general info tap make sure that you have the view set to resize from nib. Also make sure that in your general tab the start up point is set. In the deployment info.
Hope this helps
Spent way too long on this, thanks Apple! I finally discovered that I had to delete the actual UIImageView in my view controller - not just the image - in order to change to a different image. Tried renaming the images, replacing them in all different ways, deleting caches, deleting the app from the device, doing a Clean before building. The original image was gone from everywhere as far as I could see but it would still appear. Finally I added a new UIImageView on top in the view controller and this took a new image. Then I just deleted the old UIImageView and all was fine.
The solution is use the image name without the extension png.
For example, if your image file is named "img.png", only use "img".
This will show the image as invalid (?) in the editor but will show correctly on running.
This happen because the LaunchScreen.storyboard accept only images inside Assets.xcassets and the way to refer the images inside Assets.xcassets is the name of the resource without extension.
I think that use the name without extension is a workaround that work.
I had the black screen instead of my splash after localizing my app. In Localization section of the File inspector of LaunchScreen.storyboard I had only one tick for one localization. So, I added a tick for the second localization and this fixed the issue.
Answers by #SwiftArchitect and others are good, but I kept getting the black launch screen instead of my launch storyboard.
The problem ended up being that my storyboard was losing its connection to my target.
When I created it, I moved it into a different group/directory in the Project navigator, to keep things neat. BIG MISTAKE! That disconnected it from the target... it didn't matter that the group/directory it was now inside of was connected to the target!
You can tell the difference in the dropdown menu located at:
Project > General > App Icons and Launch Images > Launch Screen File
When you open that menu, you should see your storyboard as a choice to click on.
Do not type in your storyboard name manually -- that's a sign that the target membership isn't right.
I am also trying to add a launch screen, and this procedure got it to appear (thank you!), but now the app hangs there, not moving on to Main.storyboard and viewDidLoad. I have this:
Launch screen interface file base name LaunchScreen
Main storyboard file base name LaunchScreen
If I change the second LaunchScreen to Main, I do indeed get to viewDidLoad and the app's main screen, but without LaunchScreen.
Both sim and device do this. What am I missing to get to Main after LaunchScreen?

Full screen issue after manually creating an empty application in Xcode 6

Since xcode 6 didn't offer an empty application any more, I manually created one by deleting the Launch screen interface file and the Main storyboard file base name in the info.plist file, and deleted Main.storyboard and LaunchScreen.xib then. Considering that I'll drawing the UI by myself, I created a view controller without an xib file. But when I ran the app, there are black bars both on the top and the bottom. I checked the [[UIScreen mainScreen]bounds] and found out that the bounds was 480*320.
I've checked on google and there were suggestions like adding png pictures or creating a xib file, but I really wonder why the property bounds didn't get the right size.
I have met with this problem, it's because you delete your "Launch screen file" and didn't set in general tab "Launch image source".
So you need to make .xcassets file, after right click inside .xcassets file you create "New Launch Image" with name something like "LaunchImage" and set images for appropriate sizes. After that in general tab you set "Launch image source" property name with your "LaunchImage".
Step 1:
Step 2:
Step 3:
A better approach would be to keep the storyboard and everything else Xcode sets up for a single-view app, and then build out your UI programmaticly from the ViewController. That way, you inherit all the automagic stuff the SDK does during startup.
I can't tell you exactly what this automagic stuff is; but, I'm pretty sure your bug would go away if you adopted this approach.

StoryBoard Assistant Editor stopped showing associated file

Xcode storyboard assistant editor stopped showing related files.
"Automatic" is selected and "Class" is filled in Identity Inspector.
It was working before, but know it has stopped.
"Auto" or "CounterPart" modes are still woking for other files except StoryBoard.
A few days ago, I tried to update from Xcode 5 to 6, but later on gave up.
Would that have something to do with it?
With XCode 11 onwards, you can option(alt) + click on the file that you want to view in assistant editor.
Simple Fix.
Found the solution (at least worked for me), it's the same bug that causes you not to be able to create new outlets. You must delete the [DerivedData] folder:
Close the project you are working on with.
Delete the【DerivedData】folder of you project. (This folder may inside your project's folder, or inside
~/Library/Developer/XCode/DerivedData/(your project)/ ) or somewhere
else that were setup by you.
Restart Xcode.
see here.
In same case this worked for me:
Right click on ViewController file(on left pane) and choose Delete -> Remove Reference.
Right click on folder where this ViewController file was and choose Add files to .. and add this ViewController file which your just deleted.
Profit.
Deleting the Derived Data didn't work for me nor force quitting Xcode and restarting it.
The only thing that worked was deleting both the class and the storyboard (only the reference to them) and adding them back to the project.
Hope to help someone.
If anyone is wondering how to find Assistant editor in XCode 11 then
please find the steps from the below image. You can show this options
in storyboard or Xib files on upper left corner.
Maybe it's too late but just with the keyboard, you can launch a reset for associated files.
Use the keyboard :
command + option + shift + z
You can find it in the menu Xcode->View->Assistant Editor->Reset Editor.
Click first on the assistant window, then click on 'option'+'alt' and right click on the view controller that you want.
I have Xcode 13.1 and none of these solutions is working for me, but this simple solution works for me every single time. With your Storyboard and (empty) Assistant Editor open, in the upper right of the Editor window click the "Add Editor on Right" icon Editor On Right Icon, and just as promised, it will open a new editor to the right of your Storyboard and (broken) Assistant Editor, only the Assistant in THIS window will be working! Just find the "Close Window" x on your broken editor, close it, and in its place will be your shiny new working Assistant!
Full Editor View of where to click to open the new Editor On Right
Tried all the above methods whereas after simply running the app Command + B fixed this issue and I was able to select the screen under automatic.
This command on terminal fixed my issue:
defaults write com.apple.dt.XCode IDEIndexDisable 0
simply exiting and reopening Xcode worked for me.
For Xcode 8+ versions
Check at top process indicator that if Xcode is "indexing" files... if yes, then, please wait until it finishes. Once it get finished. Your file will automatically appear as counterpart in Automatic section.
If Xcode is not showing "indexing" in process bar, then perform as #Anna Chiara's Answer
I deleted ~/Library/Developer/XCode/DerivedData -> didn't work
Xcode->View->Assistant Editor->Reset Editor is disable
Finally, I figured out that the class name of File's Owner of .xib file is incorrect (the class doesn't exist). I corrected it and Assistant Editor works again.
Hope this helps you
I had the same problem. Finally this is what worked for me.
Changing the name of the ViewController File.
Change the name of the class to the new name via the Refactor tool
Refactor tool
The only thing that ended up working for me was copying over the code from the offending ViewController files and completely deleting them, then creating new ones with the exact same name and pasting in the previous code.
The assistant then linked up to the new ViewController files with no issue.
None of these answers worked for me w/ XCode 13. However, the following worked:
Rename the ViewController class to ViewController2
Update the reference in the storyboard to ViewController2
This made the assistant editor appear.
Change the name of the class back to ViewController. Change the reference in main.storyboard back to ViewController and hit enter (Step 2)
I had same issue and spent almost 2 hours of trying different aproaches finally I found something to solve problem.
I've created two or more VC at the same swift file and I think that's why IDE confused about the files.
So I suggest that you should delete your viewcontroller class and clean than reassign class.
I hope it works for you too.
For what it is worth, this was happening to me for the last couple days on 9.3 . I had just added a new build schema for an alternate debug symbol on testflight. It was not until I removed the new schema and then deleted Derived Data and restarted did it start working again. I have re-added the new schema back in and it continues to work. Not sure what the issue was, but that is what solved it for me.
In case anyone is watching I had a bizarre instance of this (Xcode 11): I deleted a View Controller that I'd done incorrectly; dropped in a new one, created the UIView and associated. BUT I didn't bother to create the outlet from the View Controller on the previous screen. Strange that it let me work for a few minutes, then after I had turned off the assistant editor to do something else, turned it back on and only had the UIResponder.h file. Edit - this happened again. Had to delete the 'wire' to the next screen, then recreate - then option to get to the correct .m and .h files reappeared.
I faced a similar issue and here's what I did
I had a swift file and a xib file with its class connected to the swift file like so inside a group folder, and it doesn't show that they're connected.
But when I take them off the folder the assistant works somehow, so I took them off the folder and made an outlet from a UILabel then put them back inside the folder then they're permenantly connected.
Quite Xcode and reopen it. This is solve my problem.
I had the same problem. But my problem was about having the VC's under "View Controller" folder. When I move VC's to main folder instead of "View Controller" folder, I was able to reach the assistant without problem. If you have the same issue like mine, you can solve by deleting all the VC's and create again under your sub folder.
Just add the Class on right side of your story board which you want to open in assistant

Resources