gpt4 book ai didi

iphone - 如何将 UITextField setInputView 设置为 UIPickerView - iphone OS :3. 1.2

转载 作者:行者123 更新时间:2023-12-03 21:18:48 26 4
gpt4 key购买 nike

我以编程方式创建了一个 UITextField 和 UIPickerView 并设置了输入 View 的文本字段到选择器 View ,但是当我将此测试应用程序上传到使用 iPhone OS: 3.1.2 的 iphone 测试设备时,它在 [textfield setInputView:picker] 执行时崩溃,但是如果上传到 iphone 测试设备上,相同的测试应用程序可以正常工作iPhone 操作系统:4.1。请让我知道如何让它在 iphone OS:3.1.2 上工作

谢谢

UIPickerView* picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0f, 480.0f, 320.0f, 270.0f)];
picker.delegate = self;
[TestViewController addSubview:picker];

UITextField* textfield = [[UITextField alloc] initWithFrame:CGRectMake(145.0f, 97.0f, 155.0f, 29.0f)];
textfield.delegate = self;

[textfield setInputView:picker]; // Crashes on execution
[TestViewController addSubview:textfield];

最佳答案

setInputView 在 iOS 3.2 及更高版本中可用。

要在 iOS 3.1.2 中实现此目的,

  1. 将委托(delegate)设置为 UITextField
  2. 在委托(delegate)方法textFieldDidBeginEditing中代码如下,

    - (void)textFieldDidBeginEditing:(UITextField *)textField
    {
    [textField resignFirstResponder];
    [pickerView setHidden:NO];
    }

关于iphone - 如何将 UITextField setInputView 设置为 UIPickerView - iphone OS :3. 1.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6951776/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com