在UITableView中的“完成”button上隐藏UIPickerview

我在UITableview的每个单元格中都有UITextField,我添加了UIPickerview作为UITextField的inputView,并在其工具栏上显示了Donebutton

我的问题是如何隐藏这个popup(Picker +工具栏)点击完成button? 并在特定单元格的文本框中显示select器的选定值?

感谢致敬

编辑:代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; PremiumProductsDescriptionCell *cell = (PremiumProductsDescriptionCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[PremiumProductsDescriptionCell alloc] initShoppingCartCellWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; } ShopProduct *p = (ShopProduct *)[[ShopProduct GetShoppingCart] objectAtIndex:indexPath.row]; cell.Quantity.text = [NSString stringWithFormat:@"%d",p.Quantity]; UIPickerView *quantityPicker = [[UIPickerView alloc] init]; quantityPicker.dataSource = self; quantityPicker.delegate = self; UIToolbar *myToolbar = [[UIToolbar alloc] initWithFrame: CGRectMake(0,0, 320, 44)]; UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(hideKeyBoard)]; quantityPicker.tag = indexPath.row; [myToolbar setItems:[NSArray arrayWithObject: doneButton] animated:NO]; cell.Quantity.inputAccessoryView = myToolbar; cell.Quantity.inputView = quantityPicker; cell.Quantity.delegate = self; return cell; } 

解决:我已经采取currentTextBox一个variables,并添加以下方法和调整其第一响应者在完成button的点击:)

 - (void)textFieldDidBeginEditing:(UITextField *)textField { currentTextBox = textField; } 

UIPopOver不能从课堂上解雇,你需要从课堂上解雇。 当用户按下完成button时,您必须从popup窗口调用类中调用解除方法

 -(void)doneButtonClikd { ParentClass *viewController=[ParentClass alloc]init]; [viewController dismissPopOver]; } 

我认为这会解决你的问题对于你的inputview-

  -(void)doneButtonclikd { [selectedTextfield resignFirstResponder]; } 

不要忘记保存当前选定的文本字段。

假设你把UIPickerView放在popup窗口中,下面是如何做到这一点:

  UIPopoverController* popover = .... UIBarButtonItem* doneButton = .... [doneButton addTarget:self action:@selector(closeMe) forControlEvents:UIControlEventTouchUpInside] // .... - (void)closeMe { // Assuming popover is really a field or something... [popover dismissPopoverAnimated:YES]; } 

使用[self.view endEditing:YES]方法。