UIPickerView行数

时间:2011-11-18 16:35:15

标签: uipickerview

如何获取UIPickerView中的项目数(行数)?我似乎找不到能告诉我这个的财产。

2 个答案:

答案 0 :(得分:1)

来自UIPicker documentation

@property(nonatomic,readonly)NSInteger numberOfComponents

  • (NSInteger的)numberOfRowsInComponent:(NSInteger的)组件;

答案 1 :(得分:1)

构建一个新的PickerViewHelper文件。为UIPickerViewDataSource委托实现此必需的方法。

@interface PickerViewHelper : UIViewController<UIPickerViewDelegate, UIPickerViewDataSource>
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;

然后在UIViewController,获取数字:

long number = [self.yourPicker numberOfRowsInComponent : 0 ];