2012-04-03 82 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]方法。