user3762713 user3762713 - 2 months ago 12
iOS Question

How to find the selected text field in iOS

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

Answer
- (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");
   }
}
Comments