在UITableView中隐藏UIPickerview On Done按钮 [英] Hide UIPickerview On Done Button in UITableView

查看:76
本文介绍了在UITableView中隐藏UIPickerview On Done按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UITableview的每个Cell中都有UITextField,我已将UIPickerview添加为UITextField的inputView,并在其工具栏上显示Done按钮

I have UITextField in each Cell of UITableview and I have added UIPickerview as inputView of UITextField and showing with Done button at its tool bar

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

My question is how can I hide this this pop up (Picker + toolbar) on click of done button ? and show selected value of picker in text box in particular cell ?

谢谢和问候

编辑:代码

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

Solved : I have taken currentTextBox a variable and added following method and resizing its first responder in done button's click :)

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


推荐答案

UIPopOver无法解雇他们class,你需要从调用类中解除它。
当用户按下完成按钮时,你必须从popover调用类调用dismiss方法

UIPopOver cant be dismissed from their class and you need to dismiss it from the calling class. You have to call dismiss method from popover calling class, when user presses the done button

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

我认为这将解决您的问题
对于您的inputview-

I think this will solve your problem For your inputview-

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

别忘了保存当前选定的文本字段。

Dont forget to save the currently selected textfield.

这篇关于在UITableView中隐藏UIPickerview On Done按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆