简体   繁体   English

如何添加按钮到settings.bundle?

[英]How to add button to settings.bundle?

I'm developing an iPhone app, and by default user keeps logged in. If he wants to logout, he should open the Settings and click a "Logout" button which would erase his data and ask for a login the next time app is opened. 我正在开发一个iPhone应用程序,默认情况下用户保持登录状态。如果他想要注销,他应该打开设置并单击“注销”按钮,这将删除他的数据,并在下次应用程序打开时要求登录。 How do I add a button like this? 如何添加这样的按钮? As in twitter settings 在twitter设置中

在此输入图像描述

As CodaFi said it is not possible. 正如CodaFi所说,这是不可能的。 However it could be a good workaround to use a toggle switch for "keep me logged in". 但是,使用切换开关“让我登录”可能是一个很好的解决方法。 And when the user turn it off you can show the login screen on next launch. 当用户将其关闭时,您可以在下次启动时显示登录屏幕。

Unfortunately, this is not possible using public APIs. 不幸的是,使用公共API是不可能的。 Bear in mind that Apple reserves many, many undocumented (and exceedingly cool) features for it and it's partner's applications. 请记住,Apple保留了许多很多未记录的(并且非常酷)功能,并且它是合作伙伴的应用程序。 You are limited to only the following: 您仅限于以下内容:

Text field : The text field type displays a title (optional) and an editable text field. 文本字段 :文本字段类型显示标题(可选)和可编辑的文本字段。 You can use this type for preferences that require the user to specify a custom string value. 您可以将此类型用于要求用户指定自定义字符串值的首选项。 The key for this type is PSTextFieldSpecifier. 这种类型的关键是PSTextFieldSpecifier。

Title : The title type displays a read-only string value. 标题 :标题类型显示只读字符串值。 You can use this type to display read-only preference values. 您可以使用此类型显示只读首选项值。 (If the preference contains cryptic or nonintuitive values, this type lets you map the possible values to custom strings.) The key for this type is PSTitleValueSpecifier. (如果首选项包含含义模糊或非直观的值,则此类型允许您将可能的值映射到自定义字符串。)此类型的键是PSTitleValueSpecifier。

Toggle switch : The toggle switch type displays an ON/OFF toggle button. 拨动开关 :拨动开关类型显示ON / OFF切换按钮。 You can use this type to configure a preference that can have only one of two values. 您可以使用此类型配置只能包含两个值之一的首选项。 Although you typically use this type to represent preferences containing Boolean values, you can also use it with preferences containing non-Boolean values. 虽然您通常使用此类型来表示包含布尔值的首选项,但您也可以将其与包含非布尔值的首选项一起使用。 The key for this type is PSToggleSwitchSpecifier. 这种类型的关键是PSToggleSwitchSpecifier。

Slider : The slider type displays a slider control. 滑块 :滑块类型显示滑块控件。 You can use this type for a preference that represents a range of values. 您可以将此类型用于表示一系列值的首选项。 The value for this type is a real number whose minimum and maximum value you specify. 此类型的值是一个实数,您指定的最小值和最大值。 The key for this type is PSSliderSpecifier. 这种类型的关键是PSSliderSpecifier。

Multivalue : The multivalue type lets the user select one value from a list of values. 多值 :多值类型允许用户从值列表中选择一个值。 You can use this type for a preference that supports a set of mutually exclusive values. 您可以将此类型用于支持一组互斥值的首选项。 The values can be of any type. 值可以是任何类型。 The key for this type is PSMultiValueSpecifier. 这种类型的关键是PSMultiValueSpecifier。

Group : The group type is for organizing groups of preferences on a single page. :组类型用于在单个页面上组织首选项组。 The group type does not represent a configurable preference. 组类型不代表可配置的首选项。 It simply contains a title string that is displayed immediately before one or more configurable preferences. 它只包含一个标题字符串,该字符串紧接在一个或多个可配置首选项之前显示。 The key for this type is PSGroupSpecifier. 这种类型的关键是PSGroupSpecifier。

Child : pane The child pane type lets the user navigate to a new page of preferences. 窗格:窗格子窗格类型允许用户导航到新的首选项页面。 You use this type to implement hierarchical preferences. 您可以使用此类型来实现分层首选项。 For more information on how you configure and use this preference type, see “Hierarchical Preferences.” The key for this type is PSChildPaneSpecifier. 有关如何配置和使用此首选项类型的详细信息,请参阅“分层首选项”。此类型的键是PSChildPaneSpecifier。

If you don't mind using the 3rd-party add-on "InAppSettingsKit" for your app's Settings, then it looks they would allow you to do what you need. 如果您不介意为应用程序的设置使用第三方附加组件“InAppSettingsKit”,那么看起来它们可以让您执行所需的操作。 I'm currently studying up on this myself, but from a quick scan through their documentation it looks like they would allow you to add buttons as well as completely custom child pane views: http://www.inappsettingskit.com/ 我目前正在研究这个问题,但是通过快速浏览他们的文档,看起来他们可以添加按钮以及完全自定义的子窗格视图: http//www.inappsettingskit.com/

On that page, study the sections "IASKButtonSpecifier" and "Custom Viewcontrollers". 在该页面上,学习“IASKButtonSpecifier”和“Custom Viewcontrollers”部分。

I'll post a follow up here to let you know how this worked out for me. 我会在这里发布一个跟进来告诉你这对我来说是如何产生的。 I'm using the InAppSettingsKit already, and love it so far. 我已经使用了InAppSettingsKit,并且喜欢它到目前为止。

Download the code and sample app from Github: https://github.com/futuretap/InAppSettingsKit 从Github下载代码和示例应用程序: https//github.com/futuretap/InAppSettingsKit

Then open the InAppSettingsKit.xcworkspace in your XCode and study how they implemented the various different types of Settings entries. 然后在XCode中打开InAppSettingsKit.xcworkspace并研究它们如何实现各种不同类型的设置条目。 They definitely support what you are looking for. 他们绝对支持你所寻找的东西。 It's really quite impressive. 这真的令人印象深刻。

Erik 埃里克

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM