【问题标题】:Hide UIPickerview On Done Button in UITableView在 UITableView 中隐藏 UIPickerview 完成按钮
【发布时间】:2012-04-03 06:28:01
【问题描述】:

我在 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;
}

【问题讨论】:

    标签: iphone ios ipad


    【解决方案1】:

    UIPopOver 不能从他们的班级中解散,您需要从调用类中解散它。 当用户按下完成按钮时,您必须从 popover 调用类调用解除方法

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

    我认为这将解决您的问题 对于您的输入视图-

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

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

    【讨论】:

    • 谢谢,但我没有使用 UIPopoverController 我刚刚设置了 UITextField 的 inputView 属性
    • 请更新您的问题并显示显示 uipickerview 的代码
    【解决方案2】:

    假设您将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];
    }
    

    【讨论】:

    • 谢谢,但我没有使用 UIPopoverController 我刚刚设置了 UITextField 的 inputView 属性
    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 2014-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多