Hardik Kothari Hardik Kothari - 4 months ago 37
iOS Question

Hide UIPickerview On Done Button in UITableView

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

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 ?

Thanks and Regards

Edit : Code

- (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;


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 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

   { ParentClass *viewController=[ParentClass alloc]init];
     [viewController dismissPopOver];

I think this will solve your problem For your inputview-

        {  [selectedTextfield resignFirstResponder];

Dont forget to save the currently selected textfield.