I made a mistake and deleted the XIB by accident. The application still works, but I can't see or edit the XIB file. How do I recreate or find the XIB?
Use source code version control (SVN or GIT) next time, and put the xibs under version control. Periodic backups (such as Time Machine) might also be helpful.
I sounds like the compiled xib (= the nib file) is still around in your build folder, if you clean your project that'll be gone too.
Unless you have a backup (always make backups!) there's not much you can do at this point. You could try and search for the nib, then try to decompile it (I've never done that, I don't know how good the result would be), but that's probably going to be more work than just starting from scratch.
Related
I have read the First Book from appcoda "Beginning programming with Swift"
One feature that I learned in said book and that I really liked while working with storyboards is the ability to refactor some storyboards when the amount of storyboards becomes too large, so at first I was doing it successfully, no problem whatsoever.
I began dividing my storyboards into smaller chunks like so
OH THE HORROR
then this happened
As soon as I pressed "refactor to storyboards" it didn't prompt me for a name as it did before but instead it renamed the new storyboard reference to "Main copy.storyboard"
Can I recover the storyboard that I lost?
When that happened, the old storyboard dissapeared and an exact copy of the main.storyboard appeared
CTROL-Z Did not work as I tried that immediately and I haven't versioned for the past 2 days or so (I know, that was really stupid)
If I can not recover the storyboard, can someone tell me why did this happen? I don't want to do this again
Btw, I am running the last version of XCode 7.2.1
Xcode may have put the lost storyboard in the Trash. Use the Finder to check. The Trash is the wastebasket-looking thing at the right or bottom end of the Dock.
If the lost file is in the Trash, you may be able to right-click it and choose “Put Back” to send it back into your project folder. You may also need to add it back to your project in Xcode using File > Add Files to “MyProject”.
I got in to the same problem. If you accidentally replaced the original storyboard with new one while refactoring, you can find the old one in project folder with a name ending with "~" symbol.
Hope you can restore it from there.
I click on the XIB via the project navigator. It opens up and immediately changes the icon to gray showing I have unsaved changes. If I save changes, click on a different file and click back to re-open it, more changes. Always modifies on open.
It happens with one XIB file in this project and a couple in another project. I'd love to know why it's happening and what I can do to fix it now and prevent it in the future.
Note: using Xcode 3.2 Build 4C199 with Snow Leopard
Edit: I've added a couple sections which got removed from the XML on one of these open/modifications
<key>outlets</key>
<dict>
<key>addEventTabBarController</key>
<string>UITabBarController</string>
<key>window</key>
<string>UIWindow</string>
</dict>
<key>superclass</key>
<string>NSObject</string>
and
<key>outlets</key>
<dict>
<key>courseTableCell</key>
<string>UITableViewCell</string>
</dict>
<key>superclass</key>
<string>UITableViewController</string>
I wound up submitting this issue to Apple. Their response was unenlightening, and talking about possible optimizations, updating meta data for new version of Xcode and the like.
I tracked 100 versions from clicking off and on the file. As Apple said, it was "optimizing" every time, but each time it simply moved some XML tags around. Never happy with it's own optimizations it moved them around the next time they were opened. I'd consider it a bug with Xcode, annoying, but mostly harmless.
This only happened with old XIBs and either moving the contents into a new XIB file or (what really happened) Storyboards got rid of the issue.
I did not want to use storyboards as suggested in one of the other answers.
Here is an alternative simple/quick fix.
Go to the Interface Builder Document Properties on the inspector when selecting the xib view file.
Then you need to
change "Deployment" to something different from Project SDK, in my case I set it to the latest iOS version (iOS 6 currently).
change the development to something different from "Previous version", in my case I set it to the latest Xcode version 4.5
I run Xcode 4.5.2 on Lion.
Hope this helps.
basic Idea...
XCode stores lots of version numbers of all different sorts of things. If you look at the XML representation of the XIB, you should find that the vast majority of these little changes are in these version numbers.
How it happens...
Whenever you do an update of Xcode, many different things within Xcode (and often inside the SDK) get updated. If you make a change to a XIB file, those version changes get stood in the XIB. So, if you happen to open a XIB file, the version changes get put into that file. As soon as you build or run the app, those changed get saved to the file.
But I haven't update Xcode in a while!
Well, whenever you did your last update, the XIB files will be updated with the new version numbers as you open them, one-by-one over time.
Edit XCode 4 is better now, (maybe), if you're tempted to vote this down then ask yourself, "Have I migrated from XCode 3 to XCode 4 using Versioning?" If no, then you have no idea what you're doing, and please don't vote on this. If you have, you know how bad you suffered, but yes this question is otherwise dead. If you do find yourself opening a legacy project, just recreate it and copy the files.
I don't know the exact answer, but I do know these things will help you find it:
XCode 4 is notorious for screwing things up.
If you put your directory into a Versioning system, (Git), then grab GitBox and save your project to give it a state and create a git repo out of it. The git repo will save the state. Gitbox will visually show you the changes.
After opening it, you'll be able to right-click on that file in GitBox and hit "see difference" or "view changes" or whatnot.
You will be auto-scrolled to the lines. If you can relate the XML to the Xib, you can figure out what changes.
I went from Lion to Snow Leopard, so I don't deal with this anymore.
I accidentally deleted my main iPhone view that was in my .xib file. This was after I had drawn my entire GUI and buttons. I was trying to delete a single button, clicked the main view and hit delete, tried to UNDO, but that didn't work.
I put a new view in the .xib file, but my original GUI appears to be gone.
Is there any way to get it back?
Thanks.
When you delete a file from xcode4, it should ask, "remove the reference" or "remove the file(physically)", but either one, try to find the file in the trash. If you are lucky enough, put back the file then add in to your project again.
Last step, start using version control system. XCode4 has build in version control system, you might give it a try (although I didnt like the XCode4 version, I use "synx", which is free).
Wait wait... back up is very important, so if you dont like version control, you can do simpler task like, zipped it the project folder, and put it in a backup folder before you start add anything new or update anything.
This looks like a bug in Interface Builder. Please file a bug at http://bugreporter.apple.com. In addition to the comments above about using version control, you can choose File->Revert to saved… to go back to the last saved version, if you haven't yet saved/closed the document.
I've made an iPad app. Now, I'm changing some UI elements in the NIB. When I run the app in the simulator none of my changes appear.
I've tried touching the project before building. Nothing is working.
Can anyone shed some insight?
It seems you are not loading the correct NIB file, or more probably you have for gotten to make the right connections in you NIB file with the owner file.
If none of these are the case we are going to need some code that shows where you load you nib and/or a NIB we can inspect ourselves. :)
Try this:
Clean the target (⇧⌘K)
Delete the app from the Simulator
Build & Run as normal.
Make sure you save the changes in Interface Builder. I've found that on occasion I've forgot to save changes there, with predictable results.
In the Simulator menu, select "Reset Content and Settings…" which wipes out anything that was there previously. Xcode saves time by not installing anything it thinks is already there. This usually works fine, but occasionally can lead to out-of-date resources not being updated.
Sometimes IB will hold onto old or bad references, and I cannot seem to remove or edit them.
EDIT I have made this a wiki question with the intention of gathering more data on the phenomenon. Answers involving situations where other coders have encountered this are welcome.
This happened to me again last night with a table controller. When I created a spike project to try and reproduce the error, the system worked the way I anticipated. Then back in the actual project the bad behavior continued, even if I remove the xib file and all controllers involved.
Creating a whole new project with none of the original (problematic) xib and nib files worked correctly.
This question is not about the specifics of this incident but about this type of incident in IB.
Does anyone know more about this type of bad IB behaviour, and possibly a more stylish way to to eliminate it than nuking the project?
Note, removing the offending IB files and recreating them in the same project has not solved this for me in the past, only whole new projects.
Answers regarding examples of when/how this glitch has been observed/created are welcome as well.
I fixed this type of caching problem by clicking File > Read Class Files ... and pointing IB to my class files. Bingo, it read them fine, and everything worked. :-)
The only real suggestion I have is to file a bug report at http://bugreporter.apple.com/ with a reproducible project as the attachment; in my experience Apple do look at these things. That said, you say that re-creating the XIB in the same project didn't fix the bug. What about replacing the other end of the link; i.e. re-create the header file and use that new header with the existing XIB? Perhaps that's sufficient to prod IB into updating its model.
I just had a project where this happened and I was banging my head trying to get it to update properly in IB 3.2 (732). I really did not want to redo the xib from scratch. I tried drag/drop of the *.h files, restarting, reloading everything and it didn't work. I also tried File->Read Class Files which didn't work. Strangely though, File->Reload All Class Files worked like a charm.
I find that File > Read Class Files fixes it for a single nib file, however the nib doesn't remain in Sync with any future changes and the fix doesn't apply to any other files in the project either.
Restarting and/or clean building didn't help either, but new projects are fine. This has been happening to me in Xcode/IB ver 3.2.2 - so far the only solution has been rebuilding the code in a new project.
Maybe not the answer you want, but here it is: Do not use IB! :-)
I had troubles using it too, even when reproducing exactly the steps as described in some Apple docs, trying multiple times from scratch. So after 3 days I just gave up and started doing everything programmatically, implementing my program in half a day. I have never looked back since. I only launch IB occasionally to look at sizes, so I can feed them into my code.
It will probably be less easy to update my GUI over time, but if your story is a real recurrent problem, I'm glad I parted ways with the beast!
When you say old or bad references, do you mean it is trying to link UI elements to outlets or actions in a class that no longer exist? If that is the case then go to the connections panel (cmd-5) and select the object in your nib file. It should show you all the connections. Any where the text is greyed out and have an exclamation mark should be deleted (hover over and click the x).
In IB, you are only connecting to a "promise" of what your class will be like when the app launches. IB normally only lets you connect stuff that can fulfil that promise, but if you change the header in Xcode there's nothing IB can do about it besides warn you.
Try making a clean build of the code and then see if the old references remain in the xib
You don't say if the problem has persisted across restarts, so I think it might be this issue: There is a rare bug in Xcode's build process where sometimes old versions of output files are stuck in the /tmp folder and won't get updated. IIRC, the easiest solution is to clean the target and reboot your computer.
Are you saving the header files? Interface Builder parses the content of your header files on disk, not the unsaved files in Xcode's editor. If you add an outlet to a header file, and switch back to IB without saving first, IB won't see the new outlet.
I had exactly the same problem with IB when I created a new project out of an old one.
I can synchronize IB with the new .h files but IB still gave the removed references (from the old project) when I right-clicked the object ( the class name "MainController" was the same from the old to the new ) even though those references did not exist in the updated code at all.
"You don't say if the problem has persisted across restarts, so I think it might be this issue: There is a rare bug in Xcode's build process where sometimes old versions of output files are stuck in the /tmp folder and won't get updated. IIRC, the easiest solution is to clean the target and reboot your computer." I tried to clean the target but it did not work.
However, once I deleted the MainManu.xib and created a new one (there would be a bit work to design the interface by hand), the old references were gone.
I experienced the same problem. It happens when I open a project made with old Xcode version. Interface Builder does not sync correctly with Xcode. Yes, I can manually update the IB cache with the 'File->Read Class Files...', but even with this method garbage remains. I mean old IBOutlet and IBAction still shows up.
Just had this type of incident and fixed it by using XCode's refactoring to rename classes to different names. Seemed to get stuff restarted.
Reading the problematic class file again has solved this problem for me.
QUICK EASY SOLUTION: - no computer restart, no new project required . . .
Unfortunately none of the suggestions in this post have fixed this issue for me (aside from restarting my computer and then starting a whole new xcode project)
MY SOLUTION...
Anyway, the only other quick fix (that works for me with Perfoce at least), is to back out (revert) my changes in my revision control system. We are using Perforce, and this seems to work just fine.
I didn't have to create a whole new xcode project, no restarting the computer, no restarting xcode even, no manual deleting of files or references, no re-references classes, no click and drag garbage to deal with, no manual settings changes, etc.
DOWNFALL...
If you are walking all around xcode and the IB for a while, and have made a lot of changes, and then all of a sudden the issue occurs... you will then of course lose everything in the files you revert... QQ
glhf
-eric
SIDE NOTE...
this is a pretty bad bug, and definitely consumes a lot of time, especially if its your first time coming across this issue (and I'm sure everyone here realizes, that time is essential to a developer). This is the first time I've ever been disappointed with apple/obj c/xcode (started 2 months ago), and i sense this won't be the last : /