开发者

How to rename an xib file in Xcode 4?

开发者 https://www.devze.com 2023-03-31 03:39 出处:网络
I renamed an xib file in Xcode4, just by开发者_StackOverflow中文版 highlighting in the project organizer and changing the name, but it seems to confuse the project. For example, if I add a new button

I renamed an xib file in Xcode4, just by开发者_StackOverflow中文版 highlighting in the project organizer and changing the name, but it seems to confuse the project. For example, if I add a new button to the view, it doesn't show up when I run the project. However, if I rename it back to the original name, it shows up. What's the correct way to rename an xib file?


Xcode can sometimes be very picky with name-changed XIBs; the way that works best for me is as follows:

  • Remove the reference to a XIB file from my open project
  • In Finder, rename the file(s)
  • Drag them back to the project

You may still encounter errors either side of this process - and on other occasions, renaming the file by a (slow) double click on said file will work.... for errors like these, I find that by going Project -> Clean will also help.

Keep us posted!


What I've done and worked like a charm is

  1. dereference it from you project but not delete the files
  2. Open .xib with a text editor and rename the class
  3. Drag drop to project again

and voila!

I know sounds a little bit awkward but that'life. If someone else has something better please say it...


I had a much bigger problem in that I was renaming a project which also required that I rename a xib. This is by no means easy. My final problem was after renaming the xib the class no longer matched because the old class was still named in the renamed xib file. I took Martijn's advice and simply edited the xib file with a text editor and renamed the class. Then I had to dereference and re-reference the xib. That did the trick.


I know it is already answered though i need to add one more thing i have faced to ...

I tried to rename MainWindow.xib to Window.xib from context menu of XCode, then i changed "Main interface" setting to relevant XIB in PLIST file ... from that time whenever i was running my App i saw SIGABRT error (Product > Clean did not help, unfortunately) ... until i completely closed and reopned me VMWare.

So in case you use Virtual Machine then it is + 1 more suggestion to answer above - RESTART your VM.

Hope this helps ...


  1. First close Xcode, and make a backup of your project folder. Then move into your project folder and rename every file and folder which contains OldName so that it now contains NewName instead.
  2. In the project folder, run following command in a terminal, to update the contents of the files in the project:

    find . -type f -exec sed -i 's/OldName/NewName/g' "{}" \;
    
  3. Open the now-renamed project in Xcode and clicked Build -> Clean All Targets.

After that, the project (with the new name) will be built successfully.

0

精彩评论

暂无评论...
验证码 换一张
取 消