I am developing one iPad application using story board.In my application i have popup view with two text fields and one button.what i need to do means if i click the button one text is need to display in the selected text box. How i find which text box is selected at the present situation? Example code is give below Please help me to complete function.
- (IBAction)buttonPressed:(id)sender {
if(//Here i need to set the condition for check selected text box is first){
texbox1.text=@"User";
}
else{
textbox2.text =@"Admin";
}
}
- (IBAction)buttonPressed:(id)sender {
if([textbox1 isFirstResponder]){
//Cursor on textbox1
texbox1.text=@"User";
}
else if([textbox2 isFirstResponder]){
//Cursor on textbox2
textbox2.text =@"Admin";
}
else{
NSLog(@"None of them have cursor");
}
}
Set Tag to your textfields
Implement UITextFieldDelegate in your class
Use this methods
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField.tag == your tag) {
selectedTextField = textField; //selectedTextField is an UITextfield variable
}
}
Use it in your IBAction
- (IBAction)buttonPressed:(UIButton *)sender {
selectedTextField.text = @"abc";
}
//Edit: something wrong with StackOverFlow's code function, doesn't display properly
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With