I can't create UIResponder nextResponder in Sw

2019-02-25 12:08发布

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.
}

1条回答
乱世女痞
2楼-- · 2019-02-25 12:43

it will be something like this

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

Hope it helps!

查看更多
登录 后发表回答