Xcode 4 .xib Create iPad Version - iphone

I have an iPhone xib I want to turn into an iPad xib. In Xcode 3 there was a "Create iPad Version" menu option. How do I do this in Xcode 4?
I currently resized my xib, but when I turn on the simulated items (Navigation Bar, etc.) it shrinks the view back down to iPhone size.

This worked for me:
Make a copy of the .xib in the Finder.
Open the copied file in a text editor.
Change "com.apple.InterfaceBuilder3.CocoaTouch.XIB" to "com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB".
Change all instances of "IBCocoaTouchFramework" to "IBIPadFramework".
Search for sizes like {480, 320} and edit them. Or just reopen the file in Xcode and use the GUI to resize items as needed.
This also works in reverse, if you need to change an iPad xib into an iPhone xib.

in Xcode 4 it's quite hidden, but the option to convert XIBS in the app still exists.
Select the target (in XCODE4 it's shown when you select the project). Once selected use the contextual menu to "Duplicate" it. It will ask if you want to "Duplicate and transition to iPad". Then all the XIBS will be duplicated with the new iPad size.

On assessing my options, these were my thoughts:
Too much of a hassle to install xcode 3 and downgrade project
Don't want to mess with .xib file format - afraid it might break something that will show itself much later
Copying the same nib is imperfect (see the explanations in this thread)
So finally, what I ended up doing that works fine is:
Create a new file, choose "UIViewController derived" class
Check the "intended for iPad" checkbox
Name the file -iPad
Delete the .h and .m corresponding to the uiviewcontroller
Now populate the new nib with the same objects, structure and connections as the original nib
Check if on iPad, if so then load the new nib else load the old nib

The feature has been removed from Xcode 4.
Right now the easiest way is to use Xcode 3 for the conversion, since the nib (.xib) file format did not change.
Xcode 3 & 4 can now be both installed on the same system by simply selecting a different folder (see installation instructions on the disk image).

Another simple way in XCode4 is: Just copy the iPhone XIB in Finder; drag the copy in your project. Open the copied XIB in XCodes build in interface builder. Change the size of the top view in your NIBs hirarchy to iPads dimensions (e.g. 1024x748 for landscape with statusbar) - everything else resizes according to the autoresizing masks.
Works perfect for me.

If you make a new nib, it will ask you if it should be sized for iPad. That might be the easiest unless you've already done a bunch of work on it.

You will have to use the older version of Interface Builder to use the "Create iPad version using autoresizing masks". There currently is no option in Xcode 4 that will do this.

Using XCode 4, all you have to do is select the (iPhone-specific) .xib file in the project navigator, then select File... --> Duplicate...
Name the new .xib file the same as your iphone-specific one, but append ~ipad to the name. All your previous connections in the view hierarchy should be unchanged in your brand-new iPad-specific .xib file.

You can use this tool I made, based on the answer from "arlomedia":
http://iphone.dizzystudios.net/ConvertToiPad
just give it the iPhone xib path

Related

My recent changes in NIB file is not displayed in ios simulator-closed

I've applied changes in interface builder for my app which has labels in it. I just changed the name and position of a label and in addition to that I changed the font of a text view in my app. When I started to run my app, the font remains the same as previous one and none of the labels are displayed in it.
Can anyone help it pls?
in Xcode try this: main menu:product:Clean
if not enough: main menu:Xcode:preferences: -> click over locations icon:
click over the little gray right arrow for derived data:
that will show you the finder folder "DerivedData": delete it.
one other thing to try: in simulator, delete your app.
quite your xcode and then again open your project . Clear your build then run your code.
You should also make sure, that the interfacebuilder file is linked to the target you are starting in simulator.
To do this, select your xib and open the File inspector. There you should see a dropdown named "Target Membership" where you can link the xib to the targets you want.
Also be sure to have the labels defined as IBOutlets in your header file and link them correctly in your xib. Easiest way to do this is using the Assistant Editor and drag the outlet to the header file.
I had the same problem - but only on the iPhone non-retina in the simulator. Cleaning the code did not help. Restarting and rebooting did not help. But removing the app from the simulator worked. Now changes to my UI show up next time I run.
To remove the app from the simulator I did it just like on a real phone. I select the app icon with the mouse and hold it down the mouse button for a few seconds. Then the icon displays a small delete icon that you can select (the app icons shakes too).

iPhone app opens to black screen after refactor proj name in xCode 4

Guys, i wonder if any one can help - My project was fully working in both the simulator and on a device, however, i renamed the project in xcode 4 (double clicking at the root of the project navigation pane, it was happy to rename any references - but now when i launch the app it only opens to the main window (yes it has outlets, all have outlets etc etc),
no code in the app delegate stops at a break point (even in didFinishLaunchingWithOptions)
so unsure what i could have missed, i have looked at other answers and everyone writes and says "missing outlet" etc.
I have dragged some backed up version of the app delegate that used to work and no difference, what could i be missing.
I do have source control, however currently in the process of merging from VSS to GIT.
thanks
lee
Check your Info.plist for what it uses as it's Main Nib File. Perhaps something changed there? Also, within the nib file itself you might have problematic connections to classes that are still named with the old name.

new xib in xcode4

I develped an iPhone app. Now i would like to do it in iPad. To do this I have to create the new .XIB files and linked to his Class.
I don't know how to create a new .xib in xcode4. Could somebody help me?
Now, to solve this problem, I create a new file with his .XIB, delete the .m & .h and link the .XIB with my class.
Thanyou.
In order to create a XIB file in XCode 4, just go to the main menu, File->New->New File..., and from there choose User Interface from the iOS section. Then choose View (if that's what you want), device family and finally save.
Hope it helps.
We also need two more nib files, one for each of the two content views we just created. To create these, single-click the Resources folder in the Groups & Files pane so that we create them in the correct place, and then press ␣N or select New File... from the File menu again. This time, when the assistant window comes up, select User Interfaces under the iPhone OS
heading in the left pane .
Select the icon for the View XIB template, which will create a nib with a content view, and then click the Next button. When prompted for a filename, type BlueView.xib. Repeat the steps to create a second nib file called YellowView.xib. Once you’ve done that, you have all the files you need. It’s time to start hooking everything together.

Could not load the image referenced from a nib in the bundle running on device

SplitView[1290:307] Could not load the "canary04.png" image referenced from a nib in the bundle with identifier "xx.co.mycompany.ipad.SplitView"
I only get the error when running on the device. There are no problems running in simulator.
I am using the image directly in interface builder with an UIImageView.
EDIT: I have added a different new image to a different nib and that works no problems.
Anyone have any ideas?
It might not be added to your Target and in XCode 4 you can do it like this:
In your Project View, click your project name
Select your target and select "Build Phases" tab
Drag your image file into your "Copy Bundle Resources" section
That fixed it for me.
The filesystem on iOS devices is case sensitive, so it's quite possibly a case issue. (Mac OS X is generally case in-sensitive, hence you've not seen this issue in the simulator.)
As such, check that you're using the same case in the code as the filename itself.
Do you have the image in a referenced folder in XCode (blue folder)? If so you have to include the folder name in the image path, something like "Images/canary04.png"
The easy way
1 Simply do a grep in command shell to find the string of the referenced image:
grep -R 'canary04.png' YourMainDirectoryFolder/*
2 It will give you (for example) an output like this:
YourProject/en.lproj/YourViewController.xib:
<textField borderStyle="roundedRect" background="canary04.png" id="19">
3 You now know which nib file and which element it is. Just go in the file and remove the reference.
Delete the blue folder where the image is.
Import again and select "Copy items if needed".
Select "Create Groups" NOT folders
Save image as PNG-24. It works for me
You can do this to check it from your storyboard, or nib. Open it as Source Code:
Then "Find" the image name in it, see if it exists but already invalid in your project, probably you have deleted or changed its name, and now it doesn't seem valid.
Have you included the file in the target? Right-click on your Target in Xcode, select Get Info and choose the "Targets" group along the top. Make sure your intended target(s) are checked.
Good Luck.
EDIT:
The text above should have read Right-click the file (canary04.png) in Xcocde and select Get Info...
Sorry for the typo.
I had this problem when I upgraded to Xcode 4.4.1. I found that although I had deleted the images (and corresponding buttons, etc.) in the storyboards, there was still mention of them in my storyboard files (in a tabBarItems field). I manually commented them out (), Product -> Clean, and I didn't get the errors any more.
I knew there must be bogus references in the storyboard as I had previously deleted my TabBar and the current App worked without problems, just with annoying messages in the console.
I had the same issue. try to
clean
build and run
it worked with me
In my case, it was because Photoshop wasn't saving my files correctly. In the file save dialog I was clicking on myfile.png in an attempt to overwrite that file, and it was saving the file with a png extension, but in photoshop format.
I had to make sure to actually change the file format to PNG before clicking on the file I wanted to overwrite, thus saving in actual png file, thus being readable by iOS. Interestingly, interface builder showed my psd-as-png files just fine.
More generically, make sure your file is, in fact, in the format you think it is and that iOS is therefore expecting.
Solution 1 :
In my case I had copied folder containing images and even checked "Destination : copy items if needed". However it has not been added to "Copy Bundle Resources" of "Build Phases".
You can add images as follows :
Select Targets
Select "Build Phases" tab
Select "Copy Bundle Resources"
Click on "+" (Plus) button just beneath it
Locate images and add it
Solution 2 :
Delete images by selecting "Move to thrash". Again add images in your project with "Destination : copy items if needed" checked.
Note : Make sure that you add images in Assets.xcassets folder and not outside it.
I was getting this error too. I will describe my scenario:
I have a subdirectory "img" which has some png's in it.
One of these png is "ic_timeprogress_000.png"
In the storyboard (visual designer) I had an imageView and the image was set to "ic_timeprogress_000.png" (not programatically). The designer showed the imageView correctly:
Although when running the app, the error was thrown.
So in the storyboard I changed (I insist: not programatically) from "ic_timeprogress_000.png" to "img/ic_timeprogress_000.png", which lead to not showing correctly the image in the designer but showing correctly when running (no error)
Although I alter imageView.image programatically, so this "initial image" isn't ever used.
Check to make sure that canary04.png exists in your project, and that it was not deleted.
My problem was that I saved the image as .jpg and changed the name to .png (was still in jpg format). It worked with simulator
Check your image name. If it contains some spaces then image will show while running in simulator but not in the device. While running it checks Case sensitive name etc.
I had a different problem in iOS 8. In my case the problem was that I selected Device Specific for the image set, and then selected iPad. Changing this back to Universal fixed the problem.
This setting can be found in the images.xcassets file, in the third column show the attributes inspector for the image set.
In this case the images wont be displayed in the storyboard or NIB file even if you have added them to images.xcassets. They also wont show in the simulator or device.
I've encountered this issue when I was trying to set image of an imageView on Interface Builder (.xib) file.
(I was using Image Assets)
I've had 2 images with theImage.jpeg and theImage#2x.jpg
Interface Builder could be able to display true images at compile time with these jpg / jpeg formats. But I've got this error in the runtime:
Could not load the "theImage" image referenced from a nib in the bundle with identifier "org.etc.etc"
Then I changed my image files formats to .png and it worked!
Try this solution too if you have different formats for images you try to set.
I also met the problem that jpeg files cannot be loaded successfully, however I solved it without changing them to png format: for example, if you have an image named "bg.jpg", don't use "bg" in storyboard (this name is listed in the dropdown selection list), instead you should explicitly write "bg.jpg" in the name field.
For programming based image view, I guess using .jpg extension like [UIImage imageNamed:#"xx.jpg"] should also work (I did't test though).
Try cleaning the project and make sure the info.plist matches the xx.co.mycompany.ipad.SplitView
Check the image name. Then check to see if you can open the image itself in paint or photoshop. If the image was created in photoshop and there were layers sometimes there is some conflict with the .png
I had the same issue, if your images are inside sub-folders, you need to choose "Create groups for subfolders" Option when you copy the resources.
I have this problem with Xcode 5, and it seems "Combine high resolution artwork" is the culprit. I opened the app bundle, and all the images were *.tiff, which caused the image to "not be found" :S
FIX:
Open project settings, and search in the top for "combine". Change that setting to NO.
For some reason, everyone is missing this essential fix.
In my case all images where displaying fine on devices with >iOS 7 but not with iOS 6.1.
The solution was that iOS7 is case sensitive but iOS 6.1 wasn't for me. I had images named like "myImageName" and also named "myimagename" witch leads my old iPhone 3 to be unable to display these images.
So renaming them solved it.
Tried each and every answer here and nothing, so here's another glitch, your icon name cannot have dots (.) because if it does (and Xcode allows you to do that!) while the icons show well in storyboard, they won't load either in the simulator or the device.
Maybe after you set the button's image, you changed the image's name.
2015 - Still having this problem. I was referencing an image that no longer existed in one of tabbed buttons.
Solution:
Simply inspect all your buttons, UIImage etc. and make sure that the image that you are referencing actually exists within your project.
I got this problem when I accidentally added another Image set to Asset Catalog file. I renamed it after I realised the mistake, but it doesn't seem to work.
Removing the file and adding it again solves the problem.
what worked for me is making sure the file's owner in interface builder has a "view" outlet.
From IB, select file's owner from "Placeholders", then in "Connections Inspector" make sure the view outlet in connected to the main view of current XIB.
This happened because i removed the main view at some point and forgot to reconnect my new view.
Hope it helps somebody else.
In my case, the issue was the image format. They were 'jpg' files, while Xcode was expecting 'png' files. Changing the file format fixed the issue.

Could not load nib in bundle on iPhone device

I'm trying to test an app I'm developing on my iPhone. To do that I changed the target from Simulator to Device on Xcode. The application is correctly uploaded to the device and it works. The main view is shown but if I try to open a secondary view, the application crashes.
On the iPhone log (I installed the iPhone configuration utility to see the console [is the only way to see the log from iPhone?]) I can see this error:
Could not load NIB in bundle
But, on the simulator it works fine. What's wrong? Any ideas?
I had the same problem and fixed it like so:
Open XCode Target
Click the "Build phases" tab
Click the "Copy bundle resources" section
Click the +
Add the missing Nib file
I've found that sometimes the device is case sensitive and the simulator is not.
What's the filename of your xib?
or
Try uninstalling the app from the simulator and installing it again - the simulator might have an old file left over from a previous run of the app - have you renamed / moved the xib at all during development?
I had a similar problem and was getting the same error. Turns out I was using the full name of the xib file in the attributes panel under "NIB Name:"
Don't use "SomeViewController.xib", just use "SomeViewController" without the ".xib" extension.
I had the same problem when invoking initWithNibName:#"MyViewController"
Changing the invocation to initWithNibName:NSStringFromClass([MyViewController class]) worked well
You can try these things:
Make sure case is correct
Use xib filename without the ".xib" extension
Remove any -(dash) or other special chars, use _(underscore)
Remove the xib file from the project and add back to the Xcode project
Check the build settings and make sure deployment is changed to currect SDK
In my case, the xib simply wasn't being copied into the bundle. Once I added the xib into the "Copy Bundle Resources" step for the application target, everything went fine.
I finally managed to solve that issue with these two steps:
In the view controller files inspector, remove any localization
(just for testing)
Ensure that you have checked the correct target membership
I don't know why it works on the simulator :(
For me, the problem was exactly what FreeAsInBeer said: the nib somehow was missing from the bundle, whereas it had been there before and worked properly in previous versions of the app.
To fix the problem, I did the following:
Select the project in the Project Navigator.
In the project settings select Build Phases.
Expand Copy Bundle Resources.
Scroll down (if necessary) and click on the + button.
In the dialog that appears, click on the Add Other... button.
Browse for the missing .XIB file in the file system.
Build and Run... the missing nib should appear when you run it.
This is just what worked for me when I got that message. Your mileage may vary, since circumstances are not always the same for everyone, but I hope this helps someone who runs into this issue.
-Evan
I ran into the same problem. In my case the nib name was "MyViewController.xib" and I renamed it to "MyView.xib". This got rid of the error.
I was also moving a project from XCode 3 to 4.2. Changing the Path type did not matter.
I had the same error message.
My problem, however was that my language settings on my phone were set on "English" and the Region on "United Kingdom". However, the file that could not be loaded was placed in the de.lproj directory.
Moving the file into the root directory solved it.
A simple mistake that might cause this error is trying to initWithNibName on an imported viewController when you are using a storyboard rather than individual Nib files. If this is the case then just init the controller instead of trying to init with a nib that doesn't exist, or init those fields with nil.
If Storyboard and no nib, change initWithNibName: bundle: to just be init OR initWithNibName:nil bundle:nil
For what its worth, I received this error when one of my tab bar buttons had the wrong class assigned to it.
I've got it to run with delete all of the localization from the xib
In the right window.
Maybe the file is in the localization folder.
I've the same problem. And my solution is remove all Localizations for the view.
I had exactly the behavior you described: works on simulator but get the "Could not load NIB in bundle" when running on the device, and the app remain stuck on the launch image.
In my case the problem was about the MainWindow.xib file that Xcode automatically created with English localization. I am supporting English and Italian in my app and realized that I was missing the localized version of MainWindow.xib for the Italian language.
Because I had no need to localize this file (it's Xcode default to create it localized) I fixed the problem by simply removing the English localization, so the same file is used independently of the localization. Another way to fix the problem would be to add the missing localized version, if you need it.
The app was crashing on the device because my device is configured for Italian language. The simulator instead was set to English and this is why the app run correctly. Just to verify, I set the simulator to Italian language and the app crashed confirming the localization problem.
I also had this problem when I loaded a child view controller from initWithCoder, which is a good place to initialise, but keep in mind you have to add it as an actual child AFTER the view has loaded.
So shift something like this:
[self addChildViewController: self.pageViewController];
[self.view addSubview: self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
...out of your init method and into viewDidLoad. Not saying this is your problem in particular but this may be helpful to others.