上一个和下一个键盘button使用静态UITableView上的UITextfields

我正在使用带有静态单元的UITableView来显示带有几个UITextFields (每个具有从9000到9015唯一的有序标记)的窗体。 当我select一个UITextField ,键盘显示出一个具有2个button的UIToolbar ,上一个和下一个。 只要在屏幕上绘制前一个或下一个UITextField ,button就可以正常工作,否则我无法select它,因为viewWithTag找不到字段。

DEMO: http : //s15.postimg.org/5xjsoiupl/ezgif_com_video_to_gif.gif

编辑:我IQKeyboardManager使用IQKeyboardManager但它有相同的错误。 如果单元格不可见,那么它们不会被检测到,因此下一个或上一个箭头被禁用。

UITextFields

 let numberToolbar = UIToolbar(frame: CGRectMake(0, 0, self.view.frame.size.width, 50)) numberToolbar.barStyle = UIBarStyle.Default numberToolbar.tintColor = color_green prev_keyboard_button = UIBarButtonItem(title: "Previous", style: UIBarButtonItemStyle.Plain, target: self, action: "keyboardPrevButtonTapped:") next_keyboard_button = UIBarButtonItem(title: "Next", style: UIBarButtonItemStyle.Plain, target: self, action: "keyboardNextButtonTapped:") numberToolbar.items = [ prev_keyboard_button, next_keyboard_button, UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil), UIBarButtonItem(title: "OK", style: UIBarButtonItemStyle.Plain, target: self, action: "keyboardOKButtonTapped:")] numberToolbar.sizeToFit() // bind vars var_input_name.inputAccessoryView = numberToolbar var_input_name.delegate = self var_input_name.tag = 9000 // 9000 + index (0,1,2,3,..) ... 

上一个和下一个代码:

 func textFieldDidBeginEditing(textField: UITextField) { // current tag current_input_tag = textField.tag // check if it is the first prev_keyboard_button.enabled = !(textField.tag == 9000) // check if it is the last next_keyboard_button.enabled = !(textField.tag == 9015) } func keyboardPrevButtonTapped(sender: UIBarButtonItem) { if current_input_tag > 9000 { // find next input if let input = self.view.viewWithTag(current_input_tag - 1) as? UITextField { input.becomeFirstResponder() } } } func keyboardNextButtonTapped(sender: UIBarButtonItem) { if current_input_tag < 9015 { // find next input if let input = self.view.viewWithTag(current_input_tag + 1) as? UITextField { input.becomeFirstResponder() } } } 

有没有办法总是绘制静态细胞,或者我应该实现这个不同?

如果卖出超出屏幕它将被释放。 不pipe你使用静态还是dynamic的单元格。 大概意见你试图find这个时刻是不存在的