jiffo
jiffo

Reputation: 7

UITextField becomeFirstResponder

I'm trying to move my first responder on using tags in a tableview cell. I've set _txtFieldActive to pick up the active UITextFields tag. I can see this when I press the next button on the keyboard via NSLog. Now however I can't seem to figure out how to resignfirstresponder on that tag, and then move my first responder onto tag 102?? I get an error on the line of code trying to assign tag 102 to *tmp.

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
  switch (textField.tag)
  {
    case 101:
      //Do Nothing do not want to close keyboard but move on to next UITextField

      if (_txtFieldActive.tag == 101)
      {NSLog(@"Tag = 101");
      UITextField *tmp = [textField.tag == 102];
      [tmp becomeFirstResponder];
  }
break;

case 102:
  [textField resignFirstResponder];
}

return YES;

}

Many thanks all for your help in advance for any pointers.

Jon.

Upvotes: 0

Views: 589

Answers (1)

nhgrif
nhgrif

Reputation: 62072

To get a reference to a view in the current view's hierarchy with a given tag, we need to call viewWithTag:.

if (_txtFieldActive.tag == 101) {
    NSLog(@"Tag = 101");
    UITextField *tmp = [self.view viewWithTag:102];
    [tmp becomeFirstResponder];
}

Try that on for size.

If this is a UITableViewController subclass rather than a UIViewController subclass, you might need [self.tableView viewWithTag:102];, but self.view should work in either case.

Upvotes: 1

Related Questions