Xcode 包括已删除的 .xib 文件!

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4980296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:13:39  来源:igfitidea点击:

Xcode Includes .xib files that have been deleted!

iphonexcode

提问by Parad0x13

I have a problem with Xcode that I can't seem to resolve. I have a view controller lets call "foobarViewController", there was a "foobarViewController.xib" to accompany it. In this controller I splish-splashed with the view to make it look the way I wanted, but decided to do it pragmatically. And so I deleted the xib from the project, cleaned all targets, restarted xcode, restarted COMPUTER, deleted the old build folder even and STILL when I compile the view includes objects that were only in the XIB file.

我有一个我似乎无法解决的 Xcode 问题。我有一个视图控制器,可以调用“foobarViewController”,它附带一个“foobarViewController.xib”。在这个控制器中,我用视图喷溅,使它看起来像我想要的那样,但决定务实地去做。因此,我从项目中删除了 xib,清理了所有目标,重新启动了 xcode,重新启动了计算机,甚至删除了旧的构建文件夹,并且在我编译视图时仍然保留了仅包含在 XIB 文件中的对象。

What is going on here?

这里发生了什么?

回答by Jonathan.

Try these 3 things:

试试这三件事:

  • Delete app from simulator
  • 从模拟器中删除应用程序

From Xcode:

从Xcode:

  • Build Menu -> Clean All Targets -> Check both boxes -> Clean
  • XCode Menu -> Empty Caches... -> Empty
  • 构建菜单 -> 清理所有目标 -> 选中两个框 -> 清理
  • XCode 菜单 -> 清空缓存... -> 清空

回答by Lily Ballard

Did you delete the app from the simulator? When Xcode installs a development build, either in the Simulator or on the device, it doesn't delete existing files. It simply overwrites files and adds new files. This means that if you delete a file from Xcode, it will be left in the already-installed built product. The solution is to delete the product from your simulator/device before installing.

您是否从模拟器中删除了该应用程序?当 Xcode 在模拟器或设备上安装开发版本时,它不会删除现有文件。它只是覆盖文件并添加新文件。这意味着如果您从 Xcode 中删除一个文件,它将留在已安装的构建产品中。解决方案是在安装之前从模拟器/设备中删除该产品。

回答by TigerCoding

Are you sure it was deleted? You may have only removed the reference to it. Open the project folder and make sure it isn't there. Better yet, do a search in spotlight for the filename.

你确定删了?您可能只是删除了对它的引用。打开项目文件夹并确保它不存在。更好的是,在聚光灯下搜索文件名。

If you can't find the file, it's still unresolvable, and you made the view controller programmatically, try pasting your code into a text editor, delete the classes, and re-make it and paste the code back in.

如果您找不到该文件,它仍然无法解析,并且您以编程方式制作了视图控制器,请尝试将您的代码粘贴到文本编辑器中,删除类,然后重新制作并粘贴代码。

回答by howanghk

The AppDelegate load the MainWindow.xib, and in the MainWindow, it include your foobarViewController.xib, therefore your problem occurs. Try editing MainWindow, point it to your controller class instead of including the xib.

AppDelegate 加载 MainWindow.xib,在 MainWindow 中,它包含您的 foobarViewController.xib,因此出现您的问题。尝试编辑 MainWindow,将其指向您的控制器类,而不是包含 xib。

回答by Tieme

check out this post: How to Empty Caches and Clean All Targets Xcode 4

查看这篇文章:如何清空缓存并清理所有目标 Xcode 4

"Command-Option-Shift-K to clean out the build folder. Even better, quit Xcode and clean out Library/Developer/Xcode/DerivedData manually. Remove all its contents because there's a bug where Xcode will run an old version of your project that's in there somewhere.

“Command-Option-Shift-K 清除构建文件夹。更好的是,退出 Xcode 并手动清除 Library/Developer/Xcode/DerivedData。删除其所有内容,因为存在一个错误,Xcode 将运行旧版本的项目那在某处。

In the simulator, choose iOS Simulator > Reset Content and Settings.

在模拟器中,选择 iOS Simulator > Reset Content and Settings。

Finally, for completeness, you can delete the contents of /var/folders; some caching happens there too." - Matt

最后,为了完整起见,您可以删除 /var/folders 的内容;一些缓存也发生在那里。” -马特

回答by sram

In XCode4, Command-Option-Shift-K should do the job. Same as product, press the option key, now the option "Clean" will change to "Clean Build Folder ..." select that option.

在 XCode4 中,Command-Option-Shift-K 应该可以完成这项工作。与产品相同,按选项键,现在选项“Clean”将更改为“Clean Build Folder ...”选择该选项。

回答by Abhay Singh

Xcode caches the xib files. Possible solutions are:

Xcode 缓存 xib 文件。可能的解决方案是:

  1. If you rename your view controller the view will contain only the newer xib file. Older elements will not be shown.

  2. In case you decide to get rid of the xib file and make the view programmatically you can override loadView method in your viewController. Over-ride this method only when you don't want to load the view from a xib file and want to create the view programmatically.

    • (void)loadView { self.view = [[[UIView alloc] init] autorelease]; }
  1. 如果您重命名视图控制器,则视图将仅包含较新的 xib 文件。旧元素将不会显示。

  2. 如果您决定删除 xib 文件并以编程方式创建视图,您可以覆盖 viewController 中的 loadView 方法。仅当您不想从 xib 文件加载视图并希望以编程方式创建视图时才覆盖此方法。

    • (void)loadView { self.view = [[[UIView alloc] init] autorelease]; }

The problem with deleting the app from device/simulator and then building it again: Users who already have the app on their device and install newer version on top of it will continue to see older xib.

从设备/模拟器中删除应用程序然后重新构建它的问题:已经在他们的设备上安装了该应用程序并在其上安装更新版本的用户将继续看到旧的 xib。

回答by Jones Agyemang

In iOS Simulator Menu > Resent Contents and Settings

在 iOS 模拟器菜单 > 重新发送内容和设置

Is sufficient.

足够了。

回答by Eyal

Sometimes it is very annoying to remove the app from the device/simulator, especially when you have saved data and configuration.

有时从设备/模拟器中删除应用程序非常烦人,尤其是当您保存了数据和配置时。

To solve this issue, for every View Controller for which you removed the .xib file add the following code:

要解决此问题,请为您删除 .xib 文件的每个视图控制器添加以下代码:

-(NSString*) nibName
{
    return nil;
}