选中行时不会删除UIPickerView

时间:2012-04-27 10:37:04

标签: objective-c ios

我选择了一个文本字段时会出现一个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];


}

但选择行时不会删除。使用所选值更新Textfield,但不删除选取器视图。我试图用作试用版.sethideen = True但它也不起作用。

非常感谢

1 个答案:

答案 0 :(得分:2)

实际上你的编码方式并不正确。当您单击textField时,您只需使用resignFirstResponder隐藏键盘并调用pickerView。您必须将pickerView inputView添加为genere而不是- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { self.genere.text =[genreArray objectAtIndex:row]; [genere resignFirstResponder]; } 。 1}} textField。然后尝试这段代码

{{1}}