I can't create UIResponder nextResponder in Swift iOS
Asked Answered
N

1

3

I have a class ASTextField which extends after UITextField and I want to define textFieldResponder.

Is any solution to write below line in Swift ??

UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];

which has been written in Objective-C below?

-(BOOL)textFieldShouldReturn:(UITextField*)textField;
{
  NSInteger nextTag = textField.tag + 1;
  // Try to find next responder
  UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
  if (nextResponder) {
    // Found next responder, so set it.
    [nextResponder becomeFirstResponder];
  } else {
    // Not found, so remove keyboard.
    [textField resignFirstResponder];
  }
  return NO; // We do not want UITextField to insert line-breaks.
}
Noah answered 22/10, 2014 at 14:37 Comment(0)
S
5

it will be something like this

let nextResponder = textField.superview?.viewWithTag(nextTag) as UIResponder!

Hope it helps!

Singapore answered 22/10, 2014 at 14:45 Comment(6)
I got an error: "UIView? does not have a member named 'viewWithTag'" :(Noah
what class is of textField.superview?Singapore
try this also let nextResponder = textField.superview?.viewWithTag(nextTag) as UIResponder!Singapore
I'm sorry, my mistake! I extends after UIView, UITextFieldDelegate :/Noah
but your answer in comment helps and I don't have "build failed", but still I can't going to next TextField ;/ only close a keyboardNoah
did it solved your issue you mentioned in question? the second is another questionSingapore

© 2022 - 2024 — McMap. All rights reserved.