[英]Hide UIPickerview On Done Button in UITableView
我在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;
}
UIPopOver無法從他們的班級被解雇,您需要從調用者班級將其解雇。 當用戶按下完成按鈕時,必須從彈出調用類中調用dismiss方法
-(void)doneButtonClikd
{ ParentClass *viewController=[ParentClass alloc]init];
[viewController dismissPopOver];
}
我認為這可以解決您的問題。
-(void)doneButtonclikd
{ [selectedTextfield resignFirstResponder];
}
不要忘記保存當前選定的文本字段。
假設您將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];
}
使用[self.view endEditing:YES]方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.