uipickerview - 用户界面选取器视图未显示

  显示原文与译文双语对照的内容

我已经以编程方式在代码中添加了用户界面选取器:


 UIPickerView *categoryList = [[UIPickerView alloc] initWithFrame:CGRectMake(10, 200, 300, 200)]; 
 categoryList.showsSelectionIndicator = YES; 
 categoryList.hidden = NO; 
 categoryList.delegate = self; 

 [cell.contentView addSubview:categoryList]; 

但是当我在模拟器上运行它时它不显示。

时间: 作者:

设置为 textField inputView

不添加 subview 。

作者:

你需要实现UIPickerViewDelegate方法来显示某些内容。

委托方法。


@Required
//returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{

}

//returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component;
{
}

另外,UIPickerViewDelegate方法用于在PickerView中显示视图或者字符串:-


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

更新:-

更改pickerView框架如下所示


UIPickerView *categoryList = [[UIPickerView alloc] initWithFrame:CGRectMake(cell.contentView.frame.origin.x+5, cell.contentView.frame.origin.y+5, 300, 200)]; 

...