简体   繁体   English

出现键盘时,UITableView的节脚正在移动

[英]Section footer of UITableView is moving when keyboard is appearing

I have a UITableView with different sections in it. 我有一个带有不同部分的UITableView。 Each section has its own footer (just a grey line for design reasons). 每个部分都有自己的页脚(出于设计原因,该行仅是一条灰线)。 When clicking on a table view cell in a section an AlertView and the keyboard appears (to enter a password). 单击部分中的表视图单元格时,将显示AlertView和键盘(输入密码)。 But when the keyboard appears the footer of the section is pushed up by the keyboard. 但是,当键盘出现时,该部分的页脚会被键盘向上推。 U can see it behind the AlertView in the grey background. 您可以在灰色背景的AlertView后面看到它。 Looks very ugly. 看起来很丑。

How can i avoid that? 我如何避免这种情况? The footer in the background should stay where it was (on the bottom of the section). 后台中的页脚应保持原样(在该部分的底部)。 Any ideas? 有任何想法吗?

There is a work around for this which worked for me, set tableView.sectionFooterHeight = 0 when textFieldShouldBeginEditing . 为此有一个解决方法,当textFieldShouldBeginEditing时将tableView.sectionFooterHeight = 0设置tableView.sectionFooterHeight = 0

func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
    tableView.beginUpdates()
    tableView.sectionFooterHeight = 0
    tableView.endUpdates()
    return true
}

func textFieldShouldEndEditing(textField: UITextField) -> Bool {
    tableView.beginUpdates()
    tableView.sectionFooterHeight = 100
    tableView.endUpdates()
    return true
}

Make sure you're setting the footerView height using tableView.sectionFooterHeight = 100 in viewDidLoad() and not using the func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat 确保您在viewDidLoad()使用tableView.sectionFooterHeight = 100而不是使用func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat来设置footerView的高度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM