【问题标题】:Show UIPicker AND keyboard显示 UIPicker 和键盘
【发布时间】:2013-12-04 15:06:33
【问题描述】:

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

当用户单击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];
}

我们需要使用软键盘在文本字段中同时显示选择器和光标。两者同时进行。我该怎么做?

【问题讨论】:

    标签: ios objective-c ios7 keyboard uipickerview


    【解决方案1】:

    所以你描述的是一系列要求。项目here 演示了您可以拥有一个活动的 Picker 和一个活动的 textField 并显示键盘。所以你想要的核心功能是由系统提供的。

    在显示键盘时应该可以将选取器动画化到视图中,并且正如演示项目所示,您可以在 textField 中点击文本并旋转选取器。

    在尝试将其集成到复杂项目之前,启动一个非常简单的演示项目来测试某些东西,以确保它是正确的,这通常真的很有帮助。

    【讨论】:

    • 感谢您的回复!实际上只有一个要求:一个选择器控件和一个键盘,它们同时出现,并且都可以被用户用来设置值。我正在评估您共享的项目,看看是否可以修改它来满足我的需要。
    • 这并不能解决我的问题。我不知道为什么我可以动态显示选择器而不是软件键盘,或者显示键盘而不是选择器。
    • 对 - 所以你还有其他问题。您的任务很复杂,您需要将其分解为更简单的部分,并让每个部分发挥作用。您最初的问题是让这两个视图一起工作,我现在展示了这些视图。因此,以该演示项目为例,将主视图设为 tableView,将 textField 添加到单元格,然后再试一次。如果你试图“强制”你当前的复杂项目工作,你可能会花费比你需要的更多的时间。由于键盘实际上是在一个窗口中覆盖了您的视图,因此尝试添加新视图可能无法正常工作。
    猜你喜欢
    • 1970-01-01
    • 2013-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-18
    • 2010-10-02
    • 1970-01-01
    • 2018-02-17
    相关资源
    最近更新 更多