UI Picker View未显示

时间:2014-10-21 08:46:40

标签: ios uipickerview tableviewcell

我已经以编程方式在我的代码中添加了一个UI Picker:

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

            [cell.contentView addSubview:categoryList];  

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

2 个答案:

答案 0 :(得分:0)

设置为textField inputView

不要添加子视图。

答案 1 :(得分:0)

您需要实现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)];