2

我有一个 UIPickerView 在选择文本字段时出现:

-(void) showPicker
{
    [self.genere resignFirstResponder];
    pickerGenero = [[UIPickerView alloc] initWithFrame:CGRectMake(0,215,320,0)];

    pickerGenero.delegate = self;
    pickerGenero.dataSource = self;
    pickerGenero.showsSelectionIndicator = YES;    

    [self.parentViewController.tabBarController.view addSubview:pickerGenero];  
    pickerGenero=nil; 
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 
{
    return [genreArray count];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;  
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    self.genere.text =[genreArray objectAtIndex:row];
    [self.pickerGenero removeFromSuperview];


}

但是在选择行时不会被删除。文本字段会使用选定的值进行更新,但不会删除选取器视图。我尝试将 .setideen=True 用作试用版,但它也不起作用。

非常感谢

4

1 回答 1

2

其实你的不是正确的编码方式。当您单击 textField 时,您只需通过使用resignFirstResponder和调用来隐藏键盘。而pickerView不是这样做,您必须为textField添加您的pickerViewas 。然后试试这段代码inputViewgenere

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    self.genere.text =[genreArray objectAtIndex:row];
    [genere resignFirstResponder];

}
于 2012-04-27T10:44:34.010 回答