ios 不小心从 Xcode 项目中删除了 xcassets 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20443306/
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
Accidentally removed xcassets file from Xcode project
提问by Aeveus
I wanted to remove a single folder from the image collection, however, I somehow managed to throw the entire xcassets file into the trash.
我想从图像集中删除一个文件夹,但是,我以某种方式设法将整个 xcassets 文件扔进了垃圾箱。
The normal 'Put back' method is not available, and simply dragging the deleted folder to Xcode yields an error:
正常的“放回”方法不可用,简单地将删除的文件夹拖到 Xcode 会产生错误:
"Images.xcassets" couldn't be copied to "ProjectPear" because an item with the same name already exists.
To save the file, either provide a different name, or move aside or delete the existing file, and try again.
无法将“Images.xcassets”复制到“ProjectPear”,因为已存在同名的项目。
要保存文件,请提供不同的名称,或者移到一边或删除现有文件,然后重试。
I'm not sure where this collection is located within my Xcode project, as the navigator doesn't appear to show anything, and the command-line isn't dropping any hints either. I'm afraid to mess around with the project.pbxproj
file, as it might jumble up a lot more than just my image collection.
我不确定这个集合在我的 Xcode 项目中的位置,因为导航器似乎没有显示任何内容,命令行也没有给出任何提示。我害怕弄乱project.pbxproj
文件,因为它可能会混淆不仅仅是我的图像集合。
Edit: Dragging the files back to Finder from Trash was successful, however, the Xcode navigator no longer recognises - or in this case, still doesn't recognise - the .xcassets file. I'm not sure whether to add something in the .pbxproj file.
编辑:将文件从垃圾箱拖回 Finder 是成功的,但是,Xcode 导航器不再识别 - 或者在这种情况下,仍然无法识别 - .xcassets 文件。我不确定是否要在 .pbxproj 文件中添加一些内容。
回答by Jason Barker
I just did this myself and figured out how to quickly remedy the issue.
我只是自己做了这个,并想出了如何快速解决这个问题。
Go to the project folder in the Finder. You should find that the folder Images.xcassetsis still there.
Move it to a separate location like to the Desktopor something. It still has all of the images and json files.
Jump back to Xcode and create a new asset catalog for images.
File > New > File... > Resource > Asset Catalog
Name it Images.
Quit Xcode and return to the Finder.
Copy the folders from within your oldImages.xcassetsto the newImages.xcassetsdirectory in your project.
Launch Xcode and you're back in business!
转到Finder 中的项目文件夹。您应该会发现文件夹Images.xcassets仍然存在。
将它移动到一个单独的位置,比如桌面或其他东西。它仍然包含所有图像和 json 文件。
跳回 Xcode 并为图像创建一个新的资产目录。
File > New > File... > Resource > Asset Catalog
将其命名为图像。
退出 Xcode 并返回 Finder。
将旧Images.xcassets 中的文件夹复制到项目中的新Images.xcassets目录中。
启动 Xcode,您就可以重新开始营业了!
回答by Finn Gaida
If you didn't delete it completely, you can just drag it back in from Finder. (Right click your project and select 'Reveal in Finder' to check)
如果您没有完全删除它,您只需从 Finder 中将其拖回即可。(右键单击您的项目并选择“在 Finder 中显示”进行检查)
If it's gone completely you simply go Cmd+N -> Resource and select Asset Catalog. You then re-add your imagages via drag and drop or right-click and 'Add Files to ...' and should be good to go.
如果它完全消失了,您只需转到 Cmd+N -> Resource 并选择 Asset Catalog。然后,您可以通过拖放或右键单击并“将文件添加到...”来重新添加您的图像,这样就可以了。
Hope that helps.
希望有帮助。
回答by Shachar
Had the same problem today with Xcode Beta, I also couldn't create a new assets catalog for some reason. This was on a Watchkit Extension Project Here's what I did to solve it:
今天在 Xcode Beta 上遇到了同样的问题,由于某种原因,我也无法创建新的资产目录。这是一个 Watchkit 扩展项目,这是我为解决它所做的:
- In finder I copied an existing images.xcassets from another folder in my app to my desktop.
- Removed the content of this folder.
- Copied a deleted (single) Image Asset from my trash into the folder (on my desktop).
- Dragged the entire folder into my project in XCode.
- 在 finder 中,我将现有的 images.xcassets 从我的应用程序中的另一个文件夹复制到我的桌面。
- 删除了此文件夹的内容。
- 将已删除(单个)图像资产从我的垃圾箱复制到文件夹(在我的桌面上)。
- 在 XCode 中将整个文件夹拖到我的项目中。
That fixed it and everything went back to normal.
这修复了它,一切都恢复正常。
回答by Ajji
Usually the file's reference is removed from Xcode, the original folder still exists in the project directory.
通常文件的引用从 Xcode 中删除,原始文件夹仍然存在于项目目录中。
Right-clickon your project folder, click "Add files to "your project"", find Assets in your project and click Addand you're done
右键单击您的项目文件夹,单击“将文件添加到“您的项目””,在您的项目中找到资产并单击“添加”,您就完成了
回答by Nupur Sharma
If you have deleted it completely, then also these are the steps to get a new Images.xcassets:
如果您已完全删除它,那么这些也是获取新 Images.xcassets 的步骤:
- In the Navigator, click on the project.
- Go to : File>New>File> Add Asset Catalog> Name it.
- To add AppIcon and LaunchImage in it:
- 在导航器中,单击项目。
- 转到:文件>新建>文件>添加资产目录>命名。
- 在其中添加 AppIcon 和 LaunchImage:
Go to the Project Setting:
进入项目设置:
- In General Tab, Slide down to App Icons and Launch Images
- Click option next to App Icons Source and select Use Asset Catalogs
- A window will pop up- select the name of your new Images.xcassets file and click on Migrate.
- Select Also add LaunchImage. Now you can see the new Images.xcassets in your project :).
- 在常规选项卡中,向下滑动到应用程序图标并启动图像
- 单击 App Icons Source 旁边的选项并选择 Use Asset Catalogs
- 将弹出一个窗口 - 选择新的 Images.xcassets 文件的名称,然后单击 Migrate。
- 选择同时添加 LaunchImage。现在你可以在你的项目中看到新的 Images.xcassets :)。
回答by Bella
I accidentally deleted the reference to the asset folder so that it was no longer visible in Xcode. But when I checked from the finder, the asset folder was still in the project folder.
我不小心删除了对资产文件夹的引用,因此它在 Xcode 中不再可见。但是当我从查找器中查看时,资产文件夹仍在项目文件夹中。
If you did that, just open the file menu in Xcode (from within your current project) and at the very top you can add (existing) files to that very project (back again) - it says "Add files to..."
如果你这样做了,只需在 Xcode 中打开文件菜单(从你当前的项目中),在最顶部你可以将(现有的)文件添加到那个项目中(再次返回) - 它说“将文件添加到...”
回答by Jey
[I realize this is a very old question from you @Aeveus] All the answers talk about re-doing the adding assets again. Given you could not undo, the one step that is missing in your original description is this:
[我意识到这是你@Aeveus 提出的一个非常古老的问题] 所有的答案都在谈论重新添加资产。鉴于您无法撤消,原始描述中缺少的一个步骤是:
In your project.pbxproj file, there would have been references to assets as below:
在您的 project.pbxproj 文件中,将有对资产的引用,如下所示:
45AE4E781C183FBA0051674F /* Assets.xcassets in Resources */ = {...
Assuming you have source code control system (git, etc) you can revert to the original contents of your project.pbxproj file, or manually just re-add the deleted lines, and re-open the project file in xcode. You are all set now.
假设您有源代码控制系统(git 等),您可以恢复到 project.pbxproj 文件的原始内容,或者手动重新添加删除的行,然后在 xcode 中重新打开项目文件。你现在都准备好了。
回答by nhgrif
Right click on anything in your project and click "Show in Finder". Search around in your project folder in the finder for a bit and you'll find it. I'm not on a Mac right now, or I'd give you a more direct path straight to the default .xcassets
folder location.
右键单击项目中的任何内容,然后单击“在 Finder 中显示”。在 finder 中的项目文件夹中搜索一下,您会找到它。我现在不在 Mac 上,或者我会给你一个直接到默认.xcassets
文件夹位置的更直接的路径。
And anyway, if you're not able to copy/create a "new" folder in that location because "an item with the same name already exists", then that means you didn't actually delete the folder. You just deleted your project's references to that folder in XCode. The folder on your hard drive didn't go anywhere.
无论如何,如果您无法在该位置复制/创建“新”文件夹,因为“已存在具有相同名称的项目”,那么这意味着您实际上并未删除该文件夹。您刚刚在 XCode 中删除了项目对该文件夹的引用。你硬盘上的文件夹没有去任何地方。
回答by Albeis
I had same problem and I have followed the steps above from Jason, but finally i got Image.xassets in red color, so the in order to find my images I had to click in Image.xassets and then on the top right corner put the absolute path to my image.xassets folder and it fixed my problem. Hope it helps!
我遇到了同样的问题,我按照 Jason 上面的步骤操作,但最后我得到了红色的 Image.xassets,所以为了找到我的图像,我必须点击 Image.xassets,然后在右上角放置我的 image.xassets 文件夹的绝对路径,它解决了我的问题。希望能帮助到你!