用整数范围填充选择器视图的最有效方法? [英] Most effective way to populate a picker view with range of integers?

查看:60
本文介绍了用整数范围填充选择器视图的最有效方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS应用(iPhone)中有一个简单的UI选择器视图,我希望在启动时使用一系列数字对其进行预填充.填充它的最实用/最快捷/最优化的方法是什么?我是iOS开发的新手,所以我才刚刚开始尝试.该文档相当不错,但是我想从经验丰富的开发人员那里获得一些有关完成我正在做的最有效方法的见识?

I have a simple UI picker view in an iOS app (iPhone) and I'm looking to pre-populate it with a range of numbers on launch. What would be the most pragmatic/quickest/optimized way to populate it? I'm new to iOS development, so I'm just starting to test the waters. The documentation is pretty decent but I'd like to get some insight from seasoned developers on the most effective way to accomplish what I'm doing?

tl; dr

我想在应用程序启动时使用数字范围45-550填充UI选择器视图,这样做的最佳方法是什么?

I want to populate a UI picker view with the the number range 45-550 upon the start of my application, what's the best way to do so?

推荐答案

尽管我可能没有资格成为经验丰富的开发人员,但我还是会这样做.在将作为数据源和选取器视图委托的类中:

Despite the possibility that I may not qualify as a seasoned developer, I would do it this way. In the class that will be the data source and delegate of the picker view:

#define PICKER_MIN 45
#define PICKER_MAX 550

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return (PICKER_MAX-PICKER_MIN+1);
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [NSString stringWithFormat:@"%d", (row+PICKER_MIN)];
}

这篇关于用整数范围填充选择器视图的最有效方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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