【发布时间】:2012-04-03 06:28:01
【问题描述】:
我在 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;
}
【问题讨论】: