What's the best way to copy xib file(s)? - iphone

I have a ViewController.xib that I would like to duplicate so I can make some settle changes to the duplicate copies. Everything is laid out how I like it in interfaceBuilder and coded correctly in the original ViewController(.M & h.). Can this be done and what is the best way to do this?

Sadly, there isn't a way to directly duplicate a file from within Xcode. I've submitted a bug to Apple on this and you should too. It's not too difficult to do manually, though:
In Xcode, right-click on the xib and choose "Show in Finder"
Once Finder comes up with the file selected, right-click on the file and choose "Duplicate"
Rename the file as you need
Drag these new files back into your Xcode project.

Using FINDER, duplicate all three files and rename them.
Drag them back into the project in Xcode.
Rename the Class in the .h & .m files & start making your subtle changes.
However, if your changes are all just to do with positioning you could just use the one file and change the frames of the things you're moving about
OR
Just duplicate the XIB file, rename it appropriately, add to the project & make the subtle changes. Then you can load the ViewController with whichever XIB suits your needs...

Related

Delete by mistake the storyboard

I delete the storyboard by mistake from my app.
Where I can find it and restore it,
or I lost it?
The default storyboard filename is Main.storyboard, so that's what you should look for unless you gave it a different name. (Older versions named it MainStoryboard.storyboard, so if you are working on an older project, you might need to look for that instead.)
First, check your project folder (using the Finder). If it's there, you can drag it back into your project in Xcode, or you can use the “Add Files to …” menu option.
If it's not there, check the trash can. If it's there, you can right-click it and choose “Put Back”, then follow the steps in the previous paragraph.
Try running again your app and Xcode will create the file automatically, this worked for me.

How to add bundles and resources like images in that bundle in iPhone

I created bundle using i-phone-OS->resources->setting but I am unable to add images to this bundle. I tried dragging images folder or by adding existing to folder but nothing works.
Thanks in advance
The Settings.bundle is added as a folder/bundle reference and not as a group.
Thus you won't be able to easily add some content to it right from the Groups & Files panel in Xcode unfortunately. Instead, go in the Finder, right-click (or ctrl-click) on this Settings.bundle and select "Show Package Contents" then drag & drop files in there. You will then find the added files back in Xcode.
I also find this kinda anoying in Xcode3 that we can't add files to '.bundle' folders/bundles directly from Xcode3 :( But AFAIK there is no other solution
One your file has been added to the '.bundle', you can edit them directly from Xcode. (Going thru the Finder is only necessary for adding new files to it)

Could not load "my-icon.png" image referenced from a nib (iPhone)

I am receiving the following error message:
2011-02-11 14:47:13.815 myProject[13177:207] Could not load the "icon-troubleshoot.png" image referenced from a nib in the bundle with identifier "com.myCompany.myProject"
This file is an old file that was being used before, but has now been deleted. As far as I know icon-troubleshoot.png is not used anywhere in my project. I tried cleaning and rebuilding, emptying caches but it didn't work. Searching for the string troubleshoot as a textual reference and "contains" selected returned nothing. Does anyone know how I can find what is causing this error?
The warning message suggests there is a reference to this png file in your .xib or .nib file(s).
Now the question is how to find it. Xcode is poor at doing this. Opening every nib file in a text editor like textedit and manual searching is time consuming.
The best solution I have for such searching tasks is to fire up terminal and use grep command. Go to source folder of your project in terminal then you can run the following in your case:
grep -i -r --include=*.xib "my-icon.png" ./
This will return all *.xib files where my-icon.png is referenced.
Later when you will see those *.xib files in xcode you'll find a '?' sign in place of my-icon.png showing that image is indeed missing as you deleted it. Now you deleted it to replace it with another image. So select '?' mark symbol, open Utilities area (to the right) and choose the correct file name. That is all.
as far as I know the search tool of x-code do not search inside the xib files that's why your search returns nothing. Anyway It's really probable there's still a reference in a xib file somewhere. Because xib files are just xml, if you don't want to check all them manually, try to open all your xib with a text editor like TextMate and perform a global text search over the content for the .png filename.
Hope this helps.
Ciao!
Clean the whole project and recompile.
There must be a reference to this file in one of the nibs. If you can't find it, try deleting the nib file where the image was used, and create a new one.
Also, check your bundle for a reference to the image file.
I had this exact same issue and I found that when I included this file in the project I didn't specify both my Development and Distribution targets, only Development, so as soon as I tried building Distribution target, it wasn't found. You have to delete reference to this image, then re-add it and make sure you checkmark all of the targets that it should be found in.
This could happen if you only have an imageName#2x.png image and have run a low resolution non-retina display build.
Cut the height and width in half in your favorite image editor and then save it in the same folder as the #2x as imageName.png
Select your storyboard object in solution explorer, right click on storyboard->"Open As"->"Source Code", now you will see xml code from storyboard. Search your image name with Cmd+F and replace or remove it.

How to "hide" files from interface builder?

My project uses a huuuge number of png file, all added as resources to the XCode Project.
Now, the problem is, whenever I try to use Interface Builder, it parses all these files, and gets terribly slow.
Is there a way to differentiate between resource files that will be used/read by code, and the one that will be used in IB?
I'm not positive, but I think IB only recognizes graphics in the root of the bundle. I think if you put the graphics in a folder and only add the folder (select the "Create Folder References" radio button) to Xcode (so it shows up blue instead of yellow), IB will ignore them. Of course you will also have to specify the new path in the code to use them.

How to copy a XIB to another project?

Simple. I have two projects in Xcode. In one of them I made a .xib file and I want to copy it to another project, so as to save some time redoing it.
I can't drag it to the other project, nor do copy/paste by command, nor copy/paste by the Edit menu.
Any suggestions?
Go into finder, find the .xib file and copy it to the directory of the second project. Then uses add existing files to add it to the second project.
Just drag and drop from one project window to the other.
Make sure that you check the "Copy items to the destination folder"
If you have more than one targets make sure that you check the appropriate target when you add it.
You probably have to reconnect all of your outlets, and if it crashes for some reason it means that there are connected outlets/actions which are not available in your code.
Here is how I managed to do this with XCode 10.2.1
Close the XCode project with the xib file you want to copy.
Drag the xib file from finder over to the new project. Make sure you tick the copy items if needed box.
If the xib file uses images for outlets, also drag the images to the new project.
There is no need to reconnect the outlets.