xcode 我可以隐藏/禁用 Settings.bundle 中的字段吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8314146/
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
Can I Hide/Disable fields in Settings.bundle?
提问by Groppe
I have several Text Field items in the Root.plist of my Settings.bundle. I need all of them for my app, but I want one of them to be either hidden or un-editable by the user. E.g. When the user goes on his iPhone to Settings-->MyApp, I want one of the fields to not be visible there, or disabled for editing. Is this possible?
我的 Settings.bundle 的 Root.plist 中有几个文本字段项。我的应用程序需要所有这些,但我希望其中一个被用户隐藏或不可编辑。例如,当用户在他的 iPhone 上进入设置--> 我的应用程序时,我希望其中一个字段在那里不可见,或者被禁用以进行编辑。这可能吗?
采纳答案by Groppe
After further research I have found the answer to my question, and the answer to the problem I am trying to solve.
经过进一步研究,我找到了我的问题的答案,以及我试图解决的问题的答案。
Question:Can you hide/disable fields in Settings.bundle/Root.plist?
Answer:No.
问题:您可以隐藏/禁用 Settings.bundle/Root.plist 中的字段吗?
回答:没有。
Problem:How do I securely store authentication information for my app?
Answer:Built in Keychain services.
问题:如何安全地存储应用程序的身份验证信息?
答:内置钥匙串服务。
Source: Keychain Services Tasks for iOS
来源:iOS 钥匙串服务任务
回答by hasan
Sure you can. Just change the item type to title.
你当然可以。只需将项目类型更改为标题即可。
You still can save and read it's value from code. but, it will not appear in the app. settings.
您仍然可以从代码中保存和读取它的值。但是,它不会出现在应用程序中。设置。
回答by Rafael Steil
Short answer, you can't. Long answer: I presume you are using the Root.plist somewhere else inside your app, is that right? If so, what I'd recommend in this case, if you really need it to work the way you described, is to create two plist files, and merge them at runtime.
简短的回答,你不能。长答案:我想你在你的应用程序内的其他地方使用了 Root.plist,是吗?如果是这样,我建议在这种情况下,如果你真的需要它按照你描述的方式工作,是创建两个 plist 文件,并在运行时合并它们。
In other words, create Root.plist with only the fields you want the user to change in the iOS settings page (e.g, without the field you are currently trying to hide), and another .plist file with the rest of the fields you want to handle inside your app.
换句话说,创建 Root.plist 仅包含您希望用户在 iOS 设置页面中更改的字段(例如,没有您当前试图隐藏的字段),以及另一个包含您想要的其余字段的 .plist 文件处理您的应用程序内部。
Then, at runtime, you first load Root.plist, and then merge the contents of the another .plist file in the data structure you'll be using.
然后,在运行时,您首先加载 Root.plist,然后将另一个 .plist 文件的内容合并到您将使用的数据结构中。
Not very slick, but could possible work.
不是很光滑,但可以工作。
回答by Carl Russmann
Setting the type in the plist from "Text Field" to "Title" works in that you get a field that is no longer editable by the user but can be read by the app.
将 plist 中的类型从“文本字段”设置为“标题”的工作原理是,您将获得一个用户不再可编辑但应用程序可以读取的字段。
It doesn't look quite right in as far as UI consistency goes, so this may not be the ideal solution to disable a preferences item.
就 UI 一致性而言,它看起来不太正确,因此这可能不是禁用首选项项的理想解决方案。