- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想使用 NSUserDefaults 存储一天中的时间值,并允许用户通过“设置”应用更新它。有没有办法存储 NSDate 对象并告诉“设置”应用仅使用时间选择器?
最佳答案
您可以将日期保存到 NSUserDefaults
。但是您不能将日期选择器添加到设置包中。在 settings.bundle plist 中没有可用的选项。更多详情 please check apple documentation
唯一的选择是,
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.
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.
Toggle switch: The toggle switch type displays an ON/OFF toggle button. 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.
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.
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.
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.
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.
为了将日期保存到用户默认值,
NSDate *currentDate = [NSDate date];
[[NSUserDefaults standardUserDefaults] setObject:currentDate forKey:@"dateKey"];
关于ios - 如何在 iPhone 首选项中存储时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13317343/
我是一名优秀的程序员,十分优秀!