繁体   English   中英

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

[英]Hide UIPickerview On Done Button in UITableView

我在UITableview的每个单元格中都有UITextField,并且已将UIPickerview添加为UITextField的inputView,并在其工具栏上显示“完成”按钮

我的问题是,单击完成按钮后如何隐藏此弹出窗口(选择器+工具栏)? 并在特定单元格的文本框中显示选择器的选定值?

谢谢并恭祝安康

编辑:代码

- (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用作变量,并添加了以下方法,并在完成按钮的单击中调整了其第一响应者的大小:)

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

UIPopOver无法从他们的班级被解雇,您需要从调用者班级将其解雇。 当用户按下完成按钮时,必须从弹出调用类中调用dismiss方法

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

我认为这可以解决您的问题。

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

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

假设您将UIPickerView放在弹出窗口中,请按照以下步骤操作:

  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]方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM