I can't create UIResponder nextResponder in Swift iOS

寵の児 提交于 2019-12-02 00:57:09

问题


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:


it will be something like this

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

Hope it helps!



来源:https://stackoverflow.com/questions/26510110/i-cant-create-uiresponder-nextresponder-in-swift-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!