2012-04-03 131 views
1

完成按钮我的UITextField在UITableView中的每个Cell,我已经加入UIPickerview作为的UITextField的inputView,并完成按钮显示在其工具栏隐藏UIPickerview论的UITableView

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

感谢和问候

编辑:代码

- (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; 
} 
调整它的第一个响应者

回答

1

UIPopOver无法从课程中解雇,您需要将其从调用课程中解雇。 你必须调用拒绝来自酥料饼的调用类,方法,当用户按下完成按钮

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

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

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

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

+0

感谢,但我不使用UIPopoverController我刚才设置的UITextField – 2012-04-03 07:09:23

+0

的inputView财产请更新您的问题,显示代码为显示uipickerview – 2012-04-03 07:10:55

+0

好吧,我已更新的代码 – 2012-04-03 07:18:25

0

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

感谢,但我不使用UIPopoverController我刚才设置的UITextField – 2012-04-03 07:09:03

+0

的inputView财产,请看看代码 – 2012-04-03 07:18:44

0

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