我用
func insertRowsAtIndexPaths(indexPaths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation)在表中插入新行的方法.但是它显示在UITableView的顶部(默认情况下).
method to insert a new Row in a table. But it appears from Top of the UITableView (by default).
我找不到任何从表格底部插入行的选项,如屏幕截图所示:
I couldn't find any option to insert rows from the bottom of the table, like on screenshot:
我尝试使用UIEdgeInsetsMake:
self.tableView.contentInset = UIEdgeInsetsMake(tableView.frame.height,0,0,0)但是当我滚动表格时,它破坏了所有设计.
but it broke all design when I scroll the table.
我的问题是:如何从表格底部插入新行?
My question is: how to insert a new rows from bottom of the table?
UPD::添加新行后,表格应该看起来像是从键盘视图移动到了NavigationBar.
UPD: It should looks like table moves from a keyboard View to NavigationBar when new row is added.
UPD2::这是我想要的: recordit.co/JoR7xuvvpG
我是在
self.tableView.contentInset = UIEdgeInsetsMake(tableView.frame.height,0,0,0)但是contentInset在行上方添加了一个大白色字段,当我向下滚动时,它隐藏了添加的行.看起来它们正隐藏在keyboardView下.我想阻止它.
But contentInset adds a big white field above the rows and when I scroll down it hides added rows. Looks like they is hiding under the keyboardView. I want to prevent it.
推荐答案感谢@raf的建议:
然后,您需要做的是在插入元素时在其父视图中为整个UITableView设置动画.如果您使用的是autolayout,请捕获属性中的Top约束,并在插入元素时将其更改为constant.像这样:
What you need to do then, is animate the whole UITableView in it's parent view up as you insert elements. If you're using autolayout, capture the Top constraint in a property, and change it's constant as you insert elements. Something like:
topConstraint.constant = newValue UIView.animateWithDuration(0.5, animations: { self.layoutIfNeeded() })更多推荐
如何在UITableView Swift底部插入新行
发布评论