返回 textField 时的 UITableView 错误
Posted
技术标签:
【中文标题】返回 textField 时的 UITableView 错误【英文标题】:UITableView bug when returning textField 【发布时间】:2016-02-10 19:58:13 【问题描述】:我使用此代码将第一响应者从一个 textField 更改为另一个。每个文本字段标签 = 行 + 100 第一个文本字段的标签(第二行)= 101 代码有效:
func textFieldShouldReturn(textField: UITextField) -> Bool
textField.textColor = UIColor.darkTextColor()
let nextTag = textField.tag + 1;
// Try to find next responder
let cell = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: nextTag-100, inSection: 0))
if(cell == nil)
return false
let nextResponder = cell!.viewWithTag(nextTag) as UIResponder!
self.view.frame.origin.y = 0
if (nextResponder != nil)
// Found next responder, so set it.
nextResponder?.becomeFirstResponder()
else
// Not found, so remove keyboard
textField.resignFirstResponder()
return false // We do not want UITextField to insert line-breaks.
要更改导航栏,我使用以下代码:
func setNavigationBar()
self.edgesForExtendedLayout = UIRectEdge.Bottom
self.extendedLayoutIncludesOpaqueBars = false
self.automaticallyAdjustsScrollViewInsets = true
self.navigationController?.navigationBarHidden = false
self.navigationController?.navigationBar.backgroundColor = UIColor.whiteColor()
self.navigationController?.navigationBar.setBackgroundImage(UIImage.fromColor(.whiteColor()), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.view.backgroundColor = UIColor.whiteColor()
self.navigationController?.navigationBar.translucent = true
self.navigationItem.setHidesBackButton(true, animated: false)
self.navigationItem.title = NSLocalizedString("REGISTRATION_TITLE", comment: "")
self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "cross_exit"), style:UIBarButtonItemStyle.Plain , target: self, action: "getBackToAuth")
self.navigationController?.navigationBar.tintColor = self.specificGrayColor
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.blackColor(),NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 17)!]
但是
self.edgesForExtendedLayout = UIRectEdge.Bottom
返回后效果消失...
before I tap next After I tap done when filled in last textField
【问题讨论】:
【参考方案1】:这可能是由 IQKeyboardSwift 库引起的。 你可以试试
override func viewWillAppear(_ animated: Bool)
super.viewWillAppear(animated)
IQKeyboardManager.shared.enable = false
override func viewWillDisappear(_ animated: Bool)
super.viewWillDisappear(animated)
IQKeyboardManager.shared.enable = true
希望能帮到你。
【讨论】:
以上是关于返回 textField 时的 UITableView 错误的主要内容,如果未能解决你的问题,请参考以下文章
iOS:UIAlertController 上的 textField 成为当前警报时的第一响应者