使用自定义 inputView 将输入返回到 UITextfield

发布于 2024-09-08 20:51:34 字数 429 浏览 5 评论 0原文

我创建了一个 UITextField 和一个自定义视图。 之后,我将此自定义视图作为“inputView”添加到我的 UITextField 中。

 amountKeyboardViewController *amountKeyboard = [[amountKeyboardViewController alloc] initWithNibName:@"amountKeyboardViewController" bundle:nil];

amountTextField.inputView = amountKeyboard.view;

[amountTextField becomeFirstResponder];

这工作得很好。但是我可以用在自定义视图(UIButtons)中单击的输入来填充“amountTextField”吗?

感谢您的一些提示!

i created a UITextField and a custom View.
after that i added this custom view as "inputView" to my UITextField.

 amountKeyboardViewController *amountKeyboard = [[amountKeyboardViewController alloc] initWithNibName:@"amountKeyboardViewController" bundle:nil];

amountTextField.inputView = amountKeyboard.view;

[amountTextField becomeFirstResponder];

this works quite fine. but can i fill my "amountTextField" with the input clicked in my custom View (UIButtons)?

thanks for some hints !

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

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

发布评论

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

评论(2

海未深 2024-09-15 20:51:35

在您的 amountTextField 控制器中,您需要在 .h 文件中编写以下代码

创建文本字段的属性

@property(nonatomic,retain)UiTextField *txt; //whatever your textfield name

现在在 .m 文件中编写以下编写以下

@synthesize txt;

语句,在其中创建 amountKeyboardViewController 对象

 amountKeyboardViewController *amountKeyboard = [[amountKeyboardViewController alloc] initWithNibName:@"amountKeyboardViewController" bundle:nil]
 amountKeyboard.objamountTextField = self;

现在在 amountKeyboardViewController 控制器中编写以下代码,

@class amountTextField;       //forward declaration

然后创建此对象类

amountTextField *objamountTextField;

创建 Now 属性

@property(nonatomic,retain)amountTextField *objamountTextField;

然后单击按钮

-(IBAction)clickof1
{
    if([amountTextField.text length] <= 0)
        objamountTextField.txt.text = @"1";
    else
        objamountTextField.txt.text=[objamountTextField.txt.text stringByAppendingString:@"1"];
}

in your amountTextField controller you need to write the following code in .h file

create property of your textfield

@property(nonatomic,retain)UiTextField *txt; //whatever your textfield name

Now in .m file write the following

@synthesize txt;

write following statement where you create object of amountKeyboardViewController

 amountKeyboardViewController *amountKeyboard = [[amountKeyboardViewController alloc] initWithNibName:@"amountKeyboardViewController" bundle:nil]
 amountKeyboard.objamountTextField = self;

Now in amountKeyboardViewController controller write the following code

@class amountTextField;       //forward declaration

then create object of this class

amountTextField *objamountTextField;

then create property of

@property(nonatomic,retain)amountTextField *objamountTextField;

Now on click of button

-(IBAction)clickof1
{
    if([amountTextField.text length] <= 0)
        objamountTextField.txt.text = @"1";
    else
        objamountTextField.txt.text=[objamountTextField.txt.text stringByAppendingString:@"1"];
}
只有影子陪我不离不弃 2024-09-15 20:51:35

您的意思是,如果您按 1,则文本字段中应显示“1”。

之后,如果您按 2,则会显示“12”。

你想要这样吗?

你必须为所有按钮编写IBaction
例如。

-(IBAction)clickof1
{
    if([amountTextField.text length] <= 0)
       amountTextField.text = @"1";
    else
       amountTextField.text = [amountTextField.text stringByAppendingString:@"1"];
}

-(IBAction)clickof2
{
    if([amountTextField.text length] <= 0)
       amountTextField.text = @"2";
    else
       amountTextField.text = [amountTextField.text stringByAppendingString:@"2"];
}

就像你必须为所有按钮编写 IBaction

You mean that if you press 1 then '1' should shown in textfield.

after that if you press 2 then it will show '12'.

Do you want like this?

You have to write IBaction for all buttons
eg.

-(IBAction)clickof1
{
    if([amountTextField.text length] <= 0)
       amountTextField.text = @"1";
    else
       amountTextField.text = [amountTextField.text stringByAppendingString:@"1"];
}

-(IBAction)clickof2
{
    if([amountTextField.text length] <= 0)
       amountTextField.text = @"2";
    else
       amountTextField.text = [amountTextField.text stringByAppendingString:@"2"];
}

like that you have to write IBaction for all your buttons

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