简体   繁体   English

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

[英]Return Inputs to UITextfield with custom inputView

i created a UITextField and a custom View. 我创建了一个UITextField和一个自定义视图。 after that i added this custom view as "inputView" to my UITextField. 之后,我将此自定义视图作为“ inputView”添加到我的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)? 但是我可以用在自定义视图(UIButtons)中单击的输入填充“ amountTextField”吗?

thanks for some hints ! 感谢您的一些提示!

You mean that if you press 1 then '1' should shown in textfield. 您的意思是,如果您按1,则应在文本字段中显示“ 1”。

after that if you press 2 then it will show '12'. 之后,如果您按数字2,它将显示“ 12”。

Do you want like this? 你要这样吗

You have to write IBaction for all buttons eg. 您必须为所有按钮编写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"];
}

like that you have to write IBaction for all your buttons 这样,您必须为所有按钮编写IBaction

in your amountTextField controller you need to write the following code in .h file 在您的amountTextField控制器中,您需要在.h文件中编写以下代码

create property of your textfield 创建文本字段的属性

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

Now in .m file write the following 现在在.m文件中编写以下内容

@synthesize txt;

write following statement where you create object of amountKeyboardViewController 写以下语句,在其中创建amountKeyboardViewController的对象

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

Now in amountKeyboardViewController controller write the following code 现在在amountKeyboardViewController控制器中编写以下代码

@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"];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM