Return Inputs to UITextfield with custom inputView

谁都会走 提交于 2019-12-01 14:23:06

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!