ios 基本国际化和多个故事板无法正常工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14773512/
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
Base internationalization and multiple storyboard not working right
提问by thomas.g
I'm playing with multiple storyboards and base localization on xCode 4.6. In fact I
我在 xCode 4.6 上使用多个故事板和基本本地化。事实上我
I did:
我做了:
1) edit my project infos localisations: checked "Use Base Internationalization" and added Languages: English, Chinese
1)编辑我的项目信息本地化:选中“使用基础国际化”并添加语言:英语,中文
2) create a new storyboard called "anotherstoryboard.storyboard"
2)创建一个名为“anotherstoryboard.storyboard”的新故事板
3) localize my new storyboard (File Inspector / Localize - Localize) using Base internationalization.
3) 使用 Base 国际化本地化我的新故事板(文件检查器/本地化 - 本地化)。
4) in my app delegate, I load dynamically my localized storyboard, like this:
4) 在我的应用程序委托中,我动态加载本地化的故事板,如下所示:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"anotherstoryboard" bundle:nil];
case 1:=> works
情况 1:=> 有效
For my new storyboard (step 3) I choose Localization Chinese - Interface Builder Cocoa Touch Storyboard
对于我的新故事板(第 3 步),我选择 Localization Chinese - Interface Builder Cocoa Touch Storyboard
It works but now I have to maintain localized storyboard, editing them with IB. I don't want such behavior, I just want to use base internationalization and localize .strings files.
它有效,但现在我必须维护本地化的故事板,用 IB 编辑它们。我不想要这种行为,我只想使用基本国际化和本地化 .strings 文件。
case 2:=> crashes
情况 2:=> 崩溃
For my new storyboard (step 3) I choose Localization Chinese - Localizable Strings
对于我的新故事板(第 3 步),我选择 Localization Chinese - Localizable Strings
The app crashes saying it can't find my storyboard
应用程序崩溃,说它找不到我的故事板
'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'anotherstoryboard' in bundle NSBundle </Users/me/Library/Application Support/iPhone Simulator/6.1/Applications/8E036C84-6058-4420-94B4-1726E1F686AD/HelloWorld.app> (loaded)'
What I'm doing wrong ? Why doesn't iOS find the right storyboard in case 2 ?
我做错了什么?为什么 iOS 没有在案例 2 中找到正确的故事板?
回答by Christopher Lenz
I had just run into the same issue (again) after starting localizing a new storyboard in Xcode 4.6.2. I checked everything was setup up properly as suggested here and elsewhere, and indeed it was.
在 Xcode 4.6.2 中开始本地化一个新的故事板后,我刚刚遇到了同样的问题(再次)。我检查了一切都按照此处和其他地方的建议正确设置,确实如此。
For me, the issue was resolved by closing the project in Xcode and manually clearing the Xcode “Derived Data” directory (see Xcode preferences) from the Finder. Then I reopened the project, made a clean build, and voilá, the storyboard got compiled properly and worked as expected.
对我来说,问题是通过关闭 Xcode 中的项目并从 Finder 手动清除 Xcode“派生数据”目录(请参阅 Xcode 首选项)来解决的。然后我重新打开了这个项目,做了一个干净的构建,瞧,故事板被正确编译并按预期工作。
回答by Alex Cio
Click on the project inside the Project Navigator
, select your project and select Info
at the top. Next you have to deselect Use Base Internationalization
and click "Remove".
单击 中的项目Project Navigator
,选择您的项目并Info
在顶部选择。接下来,您必须取消选择Use Base Internationalization
并单击“删除”。
回答by Cocoanetics
You get this error because for iOS 6 (which is required for Base Internationalization) the storyboard file gets compiled into a storyboardc file. Also it copies the strings files belonging to it to the target. Thus on an iOS 6 device there IS no .storyboard file.
您会收到此错误,因为对于 iOS 6(基本国际化所需),storyboard 文件被编译为 storyboardc 文件。它还将属于它的字符串文件复制到目标。因此,在 iOS 6 设备上没有 .storyboard 文件。
To get a storyboard file compiled you need to make sure that is in the Copy Bundle Resources build phase. Then the storyboard compiler (see build rules) kicks in and should compile it. If not, then this is a bug and you should report it.
要编译故事板文件,您需要确保它处于复制捆绑资源构建阶段。然后故事板编译器(参见构建规则)开始并应该编译它。如果没有,那么这是一个错误,您应该报告它。
回答by Albert Renshaw
I fixed the issue by dragging my story board into finder, then deleting the one in the Xcode side panel, then re-adding the one I originally dragged to finder back into the Xcode side panel. THEN removing the old RED storyboard file in "copy bundle resources" and adding the new one manually by dragging it in.
我通过将我的故事板拖到 finder 中解决了这个问题,然后删除了 Xcode 侧面板中的那个,然后重新添加了我最初拖动到 finder 的一个回到 Xcode 侧面板中。然后删除“复制捆绑资源”中的旧 RED 故事板文件,并通过将其拖入手动添加新故事板文件。
回答by who9vy
I tried exactly the same as you and I can say that this error will happen as you have shown.
我和你的尝试完全一样,我可以说这个错误会像你所展示的那样发生。
The solution is to remove and add your storyboard file from your targets build phases. Therefore, click on your target like shown in the image
解决方案是从目标构建阶段删除并添加故事板文件。因此,单击您的目标,如图所示
Then remove the storyboard file from build phases and add it again.
然后从构建阶段删除故事板文件并再次添加它。
This worked for me!
这对我有用!
回答by fir
I faced the same problem and spend 2 days to resolve it.
我遇到了同样的问题,花了 2 天的时间来解决它。
Of course I tried all things above, like: cleaning project, reseting Content and Settings in iOS Simulator, deleting all files in /Users/YourUsername/Library/Application Support/iPhone Simulator, deleting all files in /Users/YourUsername/Library/Developer/Xcode/DerivedData, deleting App in iOS device
当然,我尝试了以上所有操作,例如:清理项目、重置 iOS 模拟器中的内容和设置、删除 /Users/YourUsername/Library/Application Support/iPhone Simulator 中的所有文件、删除 /Users/YourUsername/Library/Developer 中的所有文件/Xcode/DerivedData,删除iOS设备中的App
and nothing helps me to resolve my problem - Storyboard localisation using Base Internationalization + Storyboard.strings doesn't compiles localised Storyboards.
没有什么能帮助我解决我的问题 - 使用 Base Internationalization + Storyboard.strings 的 Storyboard 本地化不会编译本地化的 Storyboard。
And the reason was that the project previously was targeted for iOS 5.1 but now for iOS 6.1. After changing Project Deployment Target I forgot to change the Compiling settings in storyboard.
原因是该项目以前针对 iOS 5.1,但现在针对 iOS 6.1。更改项目部署目标后,我忘记更改情节提要中的编译设置。
What helps me - just change "Builds for" to at least "iOS6.1 and Later" in File Inspector of your storyboard.
什么对我有帮助 - 只需在故事板的文件检查器中将“Builds for”更改为至少“iOS6.1 and later”。
回答by Nahid Ali
SOLVED
解决了
I have the problem with some arabic translations. I have tried the all possible ways mentioned in post but none worked for me.
我有一些阿拉伯语翻译的问题。我已经尝试了帖子中提到的所有可能的方法,但没有一个对我有用。
Finally i found that my Xcode is not reporting error in string file for my story board! I fixed the issue in string file and my app works as expected !
最后我发现我的 Xcode 没有在我的故事板的字符串文件中报告错误!我修复了字符串文件中的问题,我的应用程序按预期工作!
(Hint: You can also check the console for errors)
(提示:您也可以检查控制台是否有错误)
回答by mahboudz
If there is a syntax error in your Storyboard.strings file, such as a missing ; or a missing ", there doesn't seem to be any warning (Xcode 10.2.1), and you just don't get any of the localizations in that Storyboard.strings file.
如果 Storyboard.strings 文件中存在语法错误,例如缺少 ; 或缺少“,似乎没有任何警告(Xcode 10.2.1),而且您只是没有在该 Storyboard.strings 文件中获得任何本地化。
The color of the text doesn't change on the following lines to indicate an issue.
文本颜色在以下行中不会改变以指示问题。
Your best bet is to go through, line-by-line, and make sure there is nothing missing.
最好的办法是逐行检查,确保没有遗漏任何东西。
回答by samwize
Base Internationalization is only supported on iOS 6.
基础国际化仅在iOS 6上受支持。
I encountered the same problem as you, but worse, because I didn't test on iOS 5. I only knew about this after knowing many of my users experienced crashes.
我遇到了和你一样的问题,但更糟糕的是,因为我没有在 iOS 5 上测试。我是在知道我的许多用户遇到崩溃后才知道的。
So, take heed.
所以,要注意。
There are details on my blogabout this. As you already know, xib still works. Therefore, convert all strings to xib (isn't hard at all).
我的博客上有关于这方面的详细信息。如您所知,xib 仍然有效。因此,将所有字符串转换为 xib(一点也不难)。
回答by Rugmangathan
Since this was a warning and not an error, I didn't think it would be a problem at first, but eventually it was my only load. In the right sidebar, leftmost option (the icon that looks like a document), I saw a Localization section with two checkboxes, Base and English. Base was checked and English unchecked.
由于这是一个警告而不是错误,我一开始并不认为这会是一个问题,但最终它是我唯一的负担。在右侧边栏中,最左边的选项(看起来像文档的图标)中,我看到了一个带有两个复选框的本地化部分,基本和英语。基础已选中,英语未选中。
Instead, I checked English, then changed the dropdown to Interface Builder. Then I unchecked Base.
相反,我检查了英语,然后将下拉列表更改为 Interface Builder。然后我取消选中 Base。
When I checked the Build Rule again, Main.storyboard was no longer red. And when I tried to run the app in the 5.1 simulator again, it came up just fine. Note: just checking English/Interface Builder is enough to get the app to run in iOS 5.1, but then you'll run into an issue where updates to the Storyboard won't be reflected. You need to uncheck Base so that English is the only version of the storyboard there is; that way updates will always be reflected as soon as you rerun.
当我再次检查构建规则时,Main.storyboard 不再是红色的。当我再次尝试在 5.1 模拟器中运行该应用程序时,它运行得很好。注意:只需检查 English/Interface Builder 就足以让应用程序在 iOS 5.1 中运行,但随后您会遇到一个问题,即不会反映故事板的更新。您需要取消选中 Base 以便英语是故事板的唯一版本;这样,只要您重新运行,更新就会始终反映出来。