显示UIPicker和键盘

时间:2013-11-20 14:48:26

标签: ios objective-c ios7 keyboard uipickerview

我的要求要求我在UIPickerView的同时显示数字keyboard。当我单击文本字段时,我创建的数字选择器现在不会出现,尽管键盘确实如此。当我单击表格中的行时,文本字段中没有光标,但会出现选择器。

当用户点击textfield时,应显示选择器并同时显示keyboard。两者同时进行。有三个原型行:数据行,日期选择器行和数字选择器行。数字选择器还需要允许从软件keyboard输入文本。

hideExistingPickerBelowIndexPath只是添加了一个新的选择器类型行,并为数据添加了一个临时行。

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
    if (indexPath != nil)
    {
        WCHistoryItem *anItem = [self getAnItemFromIndexPath:indexPath];
        if ([anItem.type isEqualToString:kDate] || [anItem.type isEqualToString:kNumeric]) {                

            if (_isPickerVisible != NO)
            {
                [self hideExistingPickerBelowIndexPath:[NSIndexPath indexPathForRow:self.pickerIndexPath.row-1 inSection:self.pickerIndexPath.section]];
            }
            [self showNewPickerAtIndex:indexPath];
        } else {
            if (_isPickerVisible == YES) {
                [self hideExistingPickerBelowIndexPath:[NSIndexPath indexPathForRow:self.pickerIndexPath.row-1 inSection:self.pickerIndexPath.section]];
            }
        }
    }
}

-(IBAction)didBeginEditingNumericField:(UITextField*)sender
{
    WCHistoryItem *anItem = [self getAnItemFromUIView:sender];
    NSIndexPath *indexPath = [self getAnIndexPathFromUIView:sender];

    if (_isPickerVisible == NO)
    {
        //make a date cell
        [self showNewPickerAtIndex:indexPath];

    } else {
        [self hideExistingPickerBelowIndexPath:[NSIndexPath indexPathForRow:self.pickerIndexPath.row-1 inSection:self.pickerIndexPath.section]];

        [self showNewPickerAtIndex:indexPath];            
    }
    UITextField *textField = (UITextField*)sender;
    [textField becomeFirstResponder];
}

我们需要使用软件键盘在文本字段中显示选择器和光标。这两个都在同一时间。我该怎么做?

1 个答案:

答案 0 :(得分:0)

所以你所描述的是一系列要求。项目here表明您可以拥有一个活动的Picker和一个显示键盘的活动textField。因此,您需要的核心功能由系统提供。

当键盘显示时,将拾取器设置为视图应该可以正常工作,并且在演示项目显示时,您可以将文本轻击到textField并旋转选择器。

在尝试将其集成到复杂项目中之前,通常真的有助于启动一个非常简单的演示项目来测试一些东西,以确保你做对了。