何时使用plist,UIPickerView数据源帮助 [英] When to use a plist, UIPickerView datasource help

查看:60
本文介绍了何时使用plist,UIPickerView数据源帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于UIPickerView,何时将plist用于数据源?例如,如果我只想要Array 1-100,是应该在plist中还是应该在viewDidLoad中创建的东西?

For a UIPickerView, when do you use a plist for the datasource? For example, if I just wanted the Array 1-100, is that something that should be in a plist, or something that should be created in viewDidLoad?

另外,我请注意,在iPhone上时钟应用程序的UIPickerView中,数字会移动,但小时和秒这两个字保持不变。我怎么做?谢谢!

Also, I notice in the UIPickerView in the Clock app on the iPhone, the numbers move, but the words hours and seconds stay the same. How do I do that? Thanks!

推荐答案

首先,在使用plist和数组/字典之间的选择实际上只是一个选择。 plist是一种可视化的方式来查看和编辑数据,但最终您必须将其转换为NSDictionary,然后才能在代码中使用它:

Firstly, the choice between using a plist and an array/dictionary is really just a preference. The plist is good for a visual way to view and edit the data, but ultimately you will have to convert it into an NSDictionary before you can use it in your code:

NSString *path = [[NSBundle mainBundle] pathForResource:@"myplist" orType:@"plist"];
NSDictionary *plistDict = [NSDictionary dictionaryWithContentsOfFile:path];

我个人将使用awakeFromNib,initWithNibName或init等初始化方法来执行此操作,而不是使用viewDidLoad

Personally, I would do this in an initialisation method such as awakeFromNib, initWithNibName or init, rather than viewDidLoad.

最后,在选择器上获取不同列的方法是设置组件数。这是通过 UIPickerViewDataSource 方法

Finally, the way to get different columns on the picker is to set the number of components. This is done in the UIPickerViewDataSource method

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView

这是必需的。就像必须告诉您的UITableView它将有多少行和节一样。只需在 UIPickerViewDelegate 方法中提供每个组件的信息

which is required. It's the same as having to tell your UITableView how many rows and sections it will have. Simply supply the info for each component in the UIPickerViewDelegate method

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component

数据以分开的组件。

这篇关于何时使用plist,UIPickerView数据源帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆