选择器尚未显示

发布于 2024-11-02 02:45:31 字数 1127 浏览 4 评论 0原文

请我花了几个小时来解决这个问题,但没有找到解决方案并向您致辞:)

我有 UIPickerView,当用户单击 UITextField 时,它必须从视图底部显示(这就是我的应用程序要求我必须做的事情) ,所以我实现了这个方法来捕获文本字段的触摸事件:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch;
    touch=[touches anyObject];
    CGPoint point=[touch locationInView:self.view];
    if(CGRectContainsPoint([typeCarburantTextField frame],point))
    {
        [self pickerTypeCarburantsShow];

    }

}

以及这个方法来防止用户单击文本字段时显示键盘:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

    return NO;

}

pickerTypeCarburantsShow

-(IBAction)pickerTypeCarburantsShow{

        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        CGAffineTransform transform=CGAffineTransformMakeTranslation(0, 240);
        pickerViewTypesCarburants.transform=transform;
        [self.view addSubview:pickerViewTypesCarburants];
        [UIView commitAnimations];

    }

所有我的IB连接非常好,但是当我运行并单击 UITextField 时,键盘不会出现但我没有看到选择器显示 请帮忙,提前谢谢:)

please i have hours with this issue without founding solution and adressing to you for that :)

i have UIPickerView which has to be displayed from the bottom of the view when the user click on a UITextField (that's what my app requirement oblige me to do), so i implement this method to catch the touch event of the text field :

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch;
    touch=[touches anyObject];
    CGPoint point=[touch locationInView:self.view];
    if(CGRectContainsPoint([typeCarburantTextField frame],point))
    {
        [self pickerTypeCarburantsShow];

    }

}

and this method to prevent the keyboard from being displayed when the user click on the text field :

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

    return NO;

}

pickerTypeCarburantsShow

-(IBAction)pickerTypeCarburantsShow{

        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        CGAffineTransform transform=CGAffineTransformMakeTranslation(0, 240);
        pickerViewTypesCarburants.transform=transform;
        [self.view addSubview:pickerViewTypesCarburants];
        [UIView commitAnimations];

    }

all my IB connections are pretty good, however when i run and i click the UITextField the keyboard doesn't appear but i don't see the picker showed
pleaaaase help, thx in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凝望流年 2024-11-09 02:45:31

你可能想要的可能是这个。

UITextField 有这个属性,

inputView

当文本字段成为第一响应者时要显示的自定义输入视图。

@property (readwrite, retain) UIView *inputView

讨论
如果此属性中的值为 nil,则文本字段在成为第一响应者时显示标准系统键盘。将自定义视图分配给此属性会导致显示该视图。

该属性的默认值为 nil。

因此,要显示另一个视图而不是键盘,所需要做的就是设置该视图,在本例中将 uipickerview 或其容器设置为文本字段的 inputView...

例如,要显示一些 pickerview 而不是键盘,你可能想要

textView.inputView = [[UIPickerView alloc] initWithFrame:CGRectMake(...)];

What you might want is probably this one..

The UITextField has this property,

inputView

The custom input view to display when the text field becomes the first responder.

@property (readwrite, retain) UIView *inputView

Discussion
If the value in this property is nil, the text field displays the standard system keyboard when it becomes first responder. Assigning a custom view to this property causes that view to be presented instead.

The default value of this property is nil.

So, to display another view instead of the keyboard, all that is required is to set that view, in this case the uipickerview or its container as the inputView for the textfield...

for example, to show some pickerview instead of the keyboard, you might want to

textView.inputView = [[UIPickerView alloc] initWithFrame:CGRectMake(...)];
指尖凝香 2024-11-09 02:45:31

您的 PickerView 是否同时设置了委托和数据源?否则不会显示出来。

Does your PickerView have both its Delegate and DataSource set? It won't show up otherwise.

じ违心 2024-11-09 02:45:31

我的问题解决了,所以问题出在 UITextField 委托方法中,我实现了错误的方法:

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    [textField resignFirstResponder];
    return YES;
}

相反,应该是这个方法来显示 UIPickerView :

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    [textField resignFirstResponder];
    [self pickerTypeCarburantShow];
}

其中 pickerTypeCarburantShow 是一个 IBAction 方法,应该是动画整个 UIPickerView 视图..希望这可以帮助那些在同一问题上苦苦挣扎的人:)

my problem was resolved, so the problem was in the UITextField delegate method, i have implemented the wrong method :

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    [textField resignFirstResponder];
    return YES;
}

instead, it should be this method to show the UIPickerView :

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    [textField resignFirstResponder];
    [self pickerTypeCarburantShow];
}

where pickerTypeCarburantShow is an IBAction method which is supposed to animate the whole UIPickerView view.. hope this help who is struggling in the same issue :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文